Skip to content
Open
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 @@ -1493,9 +1493,6 @@ public function serialize_token(): string {
case 'IFRAME':
case 'NOEMBED':
case 'NOFRAMES':
$text = '';
break;

case 'SCRIPT':
case 'STYLE':
break;
Expand Down
98 changes: 98 additions & 0 deletions tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,108 @@ 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>" ),
'Comment text' => array( "<!-- \x00 -->", "<!-- \u{FFFD} -->" ),
);
}

/**
* Ensures that the contents of IFRAME, NOEMBED, and NOFRAMES elements are
* preserved when serializing.
*
* These elements contain raw text which is part of the parsed document.
* Dropping it would change the document's contents across a serialize and
* re-parse cycle.
*
* @ticket 65372
*
* @dataProvider data_rawtext_elements_with_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_contents() {
return array(
'IFRAME with following text' => array( '<iframe>x</iframe>y' ),
'NOEMBED with following text' => array( '<noembed>x</noembed>y' ),
'NOFRAMES with following text' => array( '<section><noframes>x</noframes>y</section>' ),
'NOFRAMES before comment' => array( '<section><noframes>x</noframes><!----></section>' ),
'IFRAME with markup-like contents' => array( '<iframe><div>inert</div></iframe>' ),
'NOEMBED with character reference' => array( '<noembed>&amp;</noembed>' ),
'NOFRAMES with character reference' => array( '<noframes>&lt;</noframes>' ),
);
}

/**
* Ensures that the contents of IFRAME, NOEMBED, and NOFRAMES elements are
* preserved when serializing full documents, including NOFRAMES elements
* in the HEAD or after a FRAMESET.
*
* @ticket 65372
*
* @dataProvider data_full_documents_with_rawtext_elements
*
* @param string $html Input HTML document.
* @param string $expected Expected serialization of the full document.
*/
public function test_rawtext_element_contents_are_preserved_in_full_documents( string $html, string $expected ) {
$processor = WP_HTML_Processor::create_full_parser( $html );

$this->assertSame(
$expected,
$processor->serialize(),
'Should have preserved the rawtext element contents.'
);
}

/**
* Data provider.
*
* @return array[]
*/
public static function data_full_documents_with_rawtext_elements() {
return array(
'IFRAME in BODY' => array(
'<iframe>x</iframe>y',
'<html><head></head><body><iframe>x</iframe>y</body></html>',
),
'NOEMBED in BODY' => array(
'a<noembed>x</noembed>',
'<html><head></head><body>a<noembed>x</noembed></body></html>',
),
'NOFRAMES in BODY' => array(
'a<noframes>x</noframes>',
'<html><head></head><body>a<noframes>x</noframes></body></html>',
),
'NOFRAMES in HEAD' => array(
'<head><noframes>x</noframes></head>z',
'<html><head><noframes>x</noframes></head><body>z</body></html>',
),
'NOFRAMES in FRAMESET' => array(
'<html><frameset><noframes>x</noframes>',
'<html><head></head><frameset><noframes>x</noframes></frameset></html>',
),
'IFRAME before a comment' => array(
'<h3><div><small><dd><iframe>x</iframe><!---->',
'<html><head></head><body><h3><div><small><dd><iframe>x</iframe><!----></dd></small></div></h3></body></html>',
),
);
}

/**
* @ticket 62396
*
Expand Down
Loading