Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1500,9 +1500,6 @@ public function serialize_token(): string {
case 'IFRAME':
case 'NOEMBED':
case 'NOFRAMES':
$text = '';
break;

case 'SCRIPT':
case 'STYLE':
case 'XMP':
Expand Down
53 changes: 36 additions & 17 deletions tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -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( "<xmp> < > & \" ' \x00 </xmp>" );

$this->assertSame(
"<xmp> < > & \" ' \u{FFFD} </xmp>",
$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( 'one</div>two</span>three' ),
Expand Down Expand Up @@ -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( "<img\x00id=5>", "<img\u{FFFD}id=5></img\u{FFFD}id=5>" ),
'Attribute name' => array( "<img/\x00id=5>", "<img \u{FFFD}id=\"5\">" ),
Expand All @@ -420,11 +404,46 @@ public static function data_tokens_with_null_bytes() {
'Foreign content text' => array( "<svg>one\x00two</svg>", "<svg>one\u{FFFD}two</svg>" ),
'SCRIPT content' => array( "<script>alert(\x00)</script>", "<script>alert(\u{FFFD})</script>" ),
'STYLE content' => array( "<style>\x00 {}</style>", "<style>\u{FFFD} {}</style>" ),
'IFRAME content' => array( "<iframe>a\x00b</iframe>", "<iframe>a\u{FFFD}b</iframe>" ),
'NOEMBED content' => array( "<noembed>a\x00b</noembed>", "<noembed>a\u{FFFD}b</noembed>" ),
'NOFRAMES content' => array( "<noframes>a\x00b</noframes>", "<noframes>a\u{FFFD}b</noframes>" ),
'XMP content' => array( "<xmp>a\x00b</xmp>", "<xmp>a\u{FFFD}b</xmp>" ),
'Comment text' => array( "<!-- \x00 -->", "<!-- \u{FFFD} -->" ),
);
}

/**
* 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<string, array{string}>
*/
public static function data_rawtext_elements_with_html_syntax_character_contents(): array {
return array(
'IFRAME' => array( 'before<iframe> < > &amp; " \' </iframe>after' ),
'NOEMBED' => array( 'before<noembed> < > &amp; " \' </noembed>after' ),
'NOFRAMES' => array( 'before<noframes> < > &amp; " \' </noframes>after' ),
'XMP' => array( 'before<xmp> < > &amp; " \' </xmp>after' ),

);
}

/**
* @ticket 62396
*
Expand Down
Loading