From c13ec34113737626058b8b68792c9e8c527dba5e Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Tue, 9 Jul 2024 13:18:29 +1200 Subject: [PATCH] FIX Don't strip `
` tag from `HTMLValue` (#11302) --- src/View/Parsers/HTMLValue.php | 2 +- tests/php/View/Parsers/HTMLValueTest.php | 28 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/View/Parsers/HTMLValue.php b/src/View/Parsers/HTMLValue.php index ee44ec1421f..76b5ebc17af 100644 --- a/src/View/Parsers/HTMLValue.php +++ b/src/View/Parsers/HTMLValue.php @@ -32,7 +32,7 @@ public function __construct($fragment = null) */ public function setContent($content) { - $content = preg_replace('#]*>#si', '', $content); + $content = preg_replace('#]*>#si', '', $content); $html5 = new HTML5(['disable_html_ns' => true]); $document = $html5->loadHTML( '' . diff --git a/tests/php/View/Parsers/HTMLValueTest.php b/tests/php/View/Parsers/HTMLValueTest.php index 7ce889dd738..52563498ace 100644 --- a/tests/php/View/Parsers/HTMLValueTest.php +++ b/tests/php/View/Parsers/HTMLValueTest.php @@ -160,4 +160,32 @@ public function testValidHTMLInNoscriptTags() $this->assertEquals($noscript, $value->getContent(), 'Child tags are left untouched in noscript tags.'); } } + + public function provideOnlyStripIntendedTags(): array + { + return [ + [ + 'input' => '

blahblah

', + 'expected' => '

blahblah

', + ], + [ + 'input' => '

blahblah

', + 'expected' => '

blahblah

', + ], + [ + 'input' => '

blahblah

', + 'expected' => '

blahblah

', + ], + ]; + } + + /** + * @dataProvider provideOnlyStripIntendedTags + */ + public function testOnlyStripIntendedTags(string $input, string $expected): void + { + $value = new HTMLValue(); + $value->setContent($input); + $this->assertEquals($expected, $value->getContent(), 'Invalid HTML can be parsed'); + } }