Fix the premature loop exit in Parser.cleanUpTocLine

When a TocLine contains elements with no children, the loop would terminate without reaching the end of the line.

Bug: T405064
Change-Id: Ica73c0166a039d9d0479e8d2357bdc610a61b42f
(cherry picked from commit 71c4df259b0fd34abe27bc957d0cebdb36547864)
This commit is contained in:
Mbergen 2025-09-23 13:12:29 +00:00 committed by A smart kitten
parent 908c2f9c46
commit 9153d6998d
2 changed files with 28 additions and 4 deletions

View file

@ -4213,10 +4213,12 @@ class Parser {
}
} else {
// Strip tag
$next = $node->firstChild;
// phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
while ( $childNode = $node->firstChild ) {
$node->parentNode->insertBefore( $childNode, $node );
if ( $node->firstChild !== null ) {
$next = $node->firstChild;
// phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
while ( $childNode = $node->firstChild ) {
$node->parentNode->insertBefore( $childNode, $node );
}
}
DOMCompat::remove( $node );
}

View file

@ -252,6 +252,28 @@ Sections:
h2 index:2 toclevel:1 number:2 title:Parser_test off:30 anchor/linkAnchor:y line:y
!! end
!! test
Ensure tags following empty tags are stripped
!! options
nohtml
showtocdata
parsoid={
"modes": [ "wt2html" ],
"wrapSections": true
}
!! wikitext
==<div></div>x==
==<abbr><abbr></abbr></abbr><abbr><abbr title="abbr title">y</abbr></abbr>z==
!! metadata/php
Sections:
h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:x line:x
h2 index:2 toclevel:1 number:2 title:Parser_test off:17 anchor/linkAnchor:yz line:yz
!! metadata/parsoid
Sections:
h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:x line:x
h2 index:2 toclevel:1 number:2 title:Parser_test off:17 anchor/linkAnchor:yz line:yz
!! end
!! test
Ensure comments in toc lines are stripped
!! config