File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -474,8 +474,14 @@ public function endTag($name)
474474 {
475475 $ lname = $ this ->normalizeTagName ($ name );
476476
477- // Ignore closing tags for unary elements.
478- if (Elements::isA ($ name , Elements::VOID_TAG )) {
477+ // Special case within 12.2.6.4.7: An end tag whose tag name is "br" should be treated as an opening tag
478+ if ($ name === 'br ' ) {
479+ $ this ->parseError ('Closing tag encountered for void element br. ' );
480+
481+ $ this ->startTag ('br ' );
482+ }
483+ // Ignore closing tags for other unary elements.
484+ elseif (Elements::isA ($ name , Elements::VOID_TAG )) {
479485 return ;
480486 }
481487
Original file line number Diff line number Diff line change @@ -715,4 +715,29 @@ public function testIAudioInParagraph()
715715 $ this ->assertSame ('p ' , $ audio ->parentNode ->nodeName );
716716 $ this ->assertSame (3 , $ audio ->childNodes ->length );
717717 }
718+
719+ public function testClosingBr ()
720+ {
721+ $ html = <<<EOM
722+ <!DOCTYPE html>
723+ <html>
724+ <head>
725+ <title>testClosingBr</title>
726+ </head>
727+ <body>
728+ <p>
729+ This line ends with a normal line break <br class="attribute-should-be-retained">
730+ This line ends with a line break marked up as a closing tag </br class="attribute-should-be-discarded">
731+ </p>
732+ </body>
733+ </html>>
734+ </html>
735+ EOM ;
736+
737+ $ dom = $ this ->parse ($ html );
738+
739+ $ this ->assertSame (2 , $ dom ->getElementsByTagName ('br ' )->length );
740+ $ this ->assertSame (1 , $ dom ->getElementsByTagName ('br ' )->item (0 )->attributes ->length );
741+ $ this ->assertSame (0 , $ dom ->getElementsByTagName ('br ' )->item (1 )->attributes ->length );
742+ }
718743}
You can’t perform that action at this time.
0 commit comments