Skip to content

Commit 3aed331

Browse files
committed
HTML API: Preserve XMP raw text serialization
1 parent 7ec1aa1 commit 3aed331

2 files changed

Lines changed: 21 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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,26 @@ 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 65372
141+
*/
142+
public function test_xmp_contents_are_not_escaped() {
143+
$normalized = WP_HTML_Processor::normalize( "<xmp>apples > or\x00anges & carrots</xmp>" );
144+
145+
$this->assertSame(
146+
"<xmp>apples > or\u{FFFD}anges & carrots</xmp>",
147+
$normalized,
148+
'Should have preserved text inside an XMP element, except for replacing NULL bytes.'
149+
);
150+
$this->assertSame(
151+
$normalized,
152+
WP_HTML_Processor::normalize( $normalized ),
153+
'Normalizing already-normalized XMP should not escape the raw text again.'
154+
);
155+
}
156+
137157
public function test_unexpected_closing_tags_are_removed() {
138158
$this->assertSame(
139159
WP_HTML_Processor::normalize( 'one</div>two</span>three' ),

0 commit comments

Comments
 (0)