Fix nested display:none span handling in CustomHtmlParser#6631
Open
HakanIST wants to merge 1 commit into
Open
Conversation
CustomHtmlParser used a single variable (lastHiddenSpanPos) to track
display:none spans. This broke when a hidden span contained child spans,
because the first inner </span> close would trigger deletion and reset
the tracker, causing subsequent nested content to leak into the output.
This is the root cause of T426910: Polish Wikipedia's {{Cite}} template
uses nested display:none spans to toggle between full names and initials.
The broken tracking produced garbled author names like
"Guy G. Mansell Guy G." instead of "Guy Mansell".
Replace the single-variable approach with depth-tracked nesting:
- hiddenSpanDepth counts nesting depth inside a display:none span
- hiddenSpanStartPos records where to truncate when the outermost
hidden span closes
- Nested span open/close events adjust the depth counter without
triggering premature deletion
Also adds CustomHtmlParserTest with 9 test cases covering simple,
nested, deeply nested, sequential, and empty hidden spans, as well
as the exact {{Cite}} template pattern from Polish Wikipedia.
Bug: T426910
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix for T426910: Citation previews for the
{{Cite}}template on Polish Wikipedia render garbled author names in the reference dialog.Root Cause
CustomHtmlParser.CustomTagHandlerused a singlelastHiddenSpanPosvariable to track<span style="display:none">elements. When a hidden span contained child spans, the first inner</span>close event would trigger output deletion and reset the tracker. Subsequent sibling spans inside the hidden parent then rendered their content as visible text.Polish Wikipedia's
{{Cite}}template uses nesteddisplay:nonespans to toggle between full author names and initials:This produced output like
Guy G. Mansell Guy G.instead ofGuy Mansell.Fix
Replace the single-variable approach with depth-tracked nesting:
hiddenSpanDepthcounts nesting depth inside adisplay:nonespanhiddenSpanStartPosrecords the output position where the outermost hidden span openedTesting
CustomHtmlParserTestwith 9 test cases covering simple, nested, deeply nested, sequential, and empty hidden spans, plus the exact{{Cite}}template pattern from Polish WikipediaStringUtilTeststill passes