diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 1828123ff879d..994b2313e78c1 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -1500,9 +1500,6 @@ public function serialize_token(): string { case 'IFRAME': case 'NOEMBED': case 'NOFRAMES': - $text = ''; - break; - case 'SCRIPT': case 'STYLE': case 'XMP': diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php b/tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php index d9d7d7c13394a..4524472742568 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php @@ -257,22 +257,6 @@ public function test_style_contents_are_not_escaped() { ); } - /** - * XMP contents are parsed using the generic raw text element parsing algorithm. - * Their contents should not be escaped with HTML character references on normalization. - * - * @ticket 65372 - */ - public function test_xmp_contents_are_not_escaped() { - $normalized = WP_HTML_Processor::normalize( " < > & \" ' \x00 " ); - - $this->assertSame( - " < > & \" ' \u{FFFD} ", - $normalized, - 'Should have preserved text inside an XMP element, except for replacing NULL bytes.' - ); - } - public function test_unexpected_closing_tags_are_removed() { $this->assertSame( WP_HTML_Processor::normalize( 'onetwothree' ), @@ -411,7 +395,7 @@ public function test_replaces_null_bytes_appropriately( string $html_with_nulls, * * @return array[] */ - public static function data_tokens_with_null_bytes() { + public static function data_tokens_with_null_bytes(): array { return array( 'Tag name' => array( "", "" ), 'Attribute name' => array( "", "" ), @@ -420,11 +404,46 @@ public static function data_tokens_with_null_bytes() { 'Foreign content text' => array( "one\x00two", "one\u{FFFD}two" ), 'SCRIPT content' => array( "", "" ), 'STYLE content' => array( "", "" ), + 'IFRAME content' => array( "", "" ), + 'NOEMBED content' => array( "a\x00b", "a\u{FFFD}b" ), + 'NOFRAMES content' => array( "a\x00b", "a\u{FFFD}b" ), 'XMP content' => array( "a\x00b", "a\u{FFFD}b" ), 'Comment text' => array( "", "" ), ); } + /** + * Ensures that contents of rawtext elements are preserved when serializing. + * + * @ticket 65372 + * + * @dataProvider data_rawtext_elements_with_html_syntax_character_contents + * + * @param string $html Normalized HTML containing a rawtext element with contents. + */ + public function test_rawtext_element_contents_are_preserved_when_normalizing( string $html ) { + $this->assertSame( + $html, + WP_HTML_Processor::normalize( $html ), + 'Should have preserved the rawtext element contents.' + ); + } + + /** + * Data provider. + * + * @return array + */ + public static function data_rawtext_elements_with_html_syntax_character_contents(): array { + return array( + 'IFRAME' => array( 'beforeafter' ), + 'NOEMBED' => array( 'before < > &amp; " \' after' ), + 'NOFRAMES' => array( 'before < > &amp; " \' after' ), + 'XMP' => array( 'before < > &amp; " \' after' ), + + ); + } + /** * @ticket 62396 *