Skip to content

Commit 5736702

Browse files
committed
HTML API: Preserve XMP rawtext serialization
1 parent 095fab5 commit 5736702

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/wp-includes/html-api/class-wp-html-processor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,7 @@ public function serialize_token(): string {
14981498

14991499
case 'SCRIPT':
15001500
case 'STYLE':
1501+
case 'XMP':
15011502
break;
15021503

15031504
default:

tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ public function test_style_contents_are_not_escaped() {
134134
);
135135
}
136136

137+
/**
138+
* Ensures that XMP contents are not escaped, as they are not parsed like text nodes are.
139+
*
140+
* @ticket 62036
141+
*/
142+
public function test_xmp_contents_are_not_escaped() {
143+
$this->assertSame(
144+
WP_HTML_Processor::normalize( "<xmp>apples > or\x00anges & pears < plums</xmp>" ),
145+
"<xmp>apples > or\u{FFFD}anges & pears < plums</xmp>",
146+
'Should have preserved text inside an XMP element, except for replacing NULL bytes.'
147+
);
148+
}
149+
137150
public function test_unexpected_closing_tags_are_removed() {
138151
$this->assertSame(
139152
WP_HTML_Processor::normalize( 'one</div>two</span>three' ),
@@ -493,6 +506,7 @@ public static function data_provider_normalized_fuzzer_cases_that_should_be_idem
493506
'FORM with SVG TITLE text edge' => array( "<form ><svg ><title \"'></form><form>" ),
494507
'FORM with TABLE and SCRIPT' => array( '<form id><table te"><script></script><td srce" ID/></form><form claslicate">' ),
495508
'FORM with TABLE CAPTION' => array( '<form><table><caption></form><form >' ),
509+
'XMP rawtext with entity-looking text' => array( '<xmp>apples > oranges &amp; <</xmp>' ),
496510
'Short malformed G attribute C' => array( '<g c/=>' ),
497511
'Short malformed G attribute S' => array( '<g s/=>' ),
498512
'Duplicate SRC boundary' => array( '<g src=""g src="">' ),

0 commit comments

Comments
 (0)