diff --git a/includes/CommentModifier.php b/includes/CommentModifier.php index edc6827e9..384f44867 100644 --- a/includes/CommentModifier.php +++ b/includes/CommentModifier.php @@ -346,7 +346,13 @@ class CommentModifier { while ( static::allOfType( $fragment->childNodes, 'dl' ) || static::allOfType( $fragment->childNodes, 'ul' ) || - static::allOfType( $fragment->childNodes, 'ol' ) + static::allOfType( $fragment->childNodes, 'ol' ) || + ( + // Or if the comment starts with a bullet followed by indents + count( $fragment->childNodes ) > 1 && + static::allOfType( [ $fragment->childNodes[0] ], 'ul' ) && + static::allOfType( array_slice( iterator_to_array( $fragment->childNodes ), 1 ), 'dl' ) + ) ) { // Do not iterate over childNodes while we're modifying it $childNodeList = iterator_to_array( $fragment->childNodes ); diff --git a/tests/phpunit/CommentModifierTest.php b/tests/phpunit/CommentModifierTest.php index e28efb15a..ba4c887cf 100644 --- a/tests/phpunit/CommentModifierTest.php +++ b/tests/phpunit/CommentModifierTest.php @@ -124,6 +124,23 @@ class CommentModifierTest extends IntegrationTestCase { return static::getJson( '../cases/unwrap.json' ); } + /** + * @dataProvider provideUnwrapFragment + */ + public function testUnwrapFragment( string $html, string $expected ): void { + $doc = static::createDocument( '' ); + $container = DOMUtils::parseHTMLToFragment( $doc, $html ); + CommentModifier::unwrapFragment( $container ); + static::assertEquals( $expected, DOMUtils::getFragmentInnerHTML( $container ) ); + } + + public static function provideUnwrapFragment() { + yield [ + "\n
bbb
", + "

aaa

\n

bbb

", + ]; + } + /** * @dataProvider provideAppendSignature */