Loading core/lib/Drupal/Component/Utility/Html.php +5 −10 Original line number Diff line number Diff line Loading @@ -275,18 +275,13 @@ public static function normalize($html) { * A \DOMDocument that represents the loaded HTML snippet. */ public static function load($html) { $document = <<<EOD <!DOCTYPE html> <html> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head> <body>$html</body> </html> EOD; // Instantiate the HTML5 parser, but without the HTML5 namespace being // added to the DOM document. $html5 = new HTML5(['disable_html_ns' => TRUE]); return $html5->loadHTML($document); $html5 = new HTML5(['disable_html_ns' => TRUE, 'encoding' => 'UTF-8']); // Attach the provided HTML inside the body. Rely on the HTML5 parser to // close the body tag. return $html5->loadHTML('<body>' . $html); } /** Loading core/modules/filter/tests/src/Kernel/FilterKernelTest.php +3 −0 Original line number Diff line number Diff line Loading @@ -1008,6 +1008,9 @@ public function testHtmlCorrectorFilter() { $f = Html::normalize('<p>text'); $this->assertEquals('<p>text</p>', $f, 'HTML corrector -- tag closing at the end of input.'); $f = Html::normalize('<p>text <img alt="ao'); $this->assertEquals('<p>text <img alt="ao"></p>', $f, 'HTML corrector -- tag closing at the end of input + broken attribute.'); $f = Html::normalize('<p>text<p><p>text'); $this->assertEquals('<p>text</p><p></p><p>text</p>', $f, 'HTML corrector -- tag closing.'); Loading Loading
core/lib/Drupal/Component/Utility/Html.php +5 −10 Original line number Diff line number Diff line Loading @@ -275,18 +275,13 @@ public static function normalize($html) { * A \DOMDocument that represents the loaded HTML snippet. */ public static function load($html) { $document = <<<EOD <!DOCTYPE html> <html> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head> <body>$html</body> </html> EOD; // Instantiate the HTML5 parser, but without the HTML5 namespace being // added to the DOM document. $html5 = new HTML5(['disable_html_ns' => TRUE]); return $html5->loadHTML($document); $html5 = new HTML5(['disable_html_ns' => TRUE, 'encoding' => 'UTF-8']); // Attach the provided HTML inside the body. Rely on the HTML5 parser to // close the body tag. return $html5->loadHTML('<body>' . $html); } /** Loading
core/modules/filter/tests/src/Kernel/FilterKernelTest.php +3 −0 Original line number Diff line number Diff line Loading @@ -1008,6 +1008,9 @@ public function testHtmlCorrectorFilter() { $f = Html::normalize('<p>text'); $this->assertEquals('<p>text</p>', $f, 'HTML corrector -- tag closing at the end of input.'); $f = Html::normalize('<p>text <img alt="ao'); $this->assertEquals('<p>text <img alt="ao"></p>', $f, 'HTML corrector -- tag closing at the end of input + broken attribute.'); $f = Html::normalize('<p>text<p><p>text'); $this->assertEquals('<p>text</p><p></p><p>text</p>', $f, 'HTML corrector -- tag closing.'); Loading