HTML API: Expect closer on foreign content void lookalike elements.

Ensure that `expects_closer` returns `false` on tags that look like void HTML tags, but are actually ''not'' void tags in foreign content.

Props jonsurrell, bernhard-reiter.
Fixes #62363.

git-svn-id: https://develop.svn.wordpress.org/trunk@59392 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
bernhard-reiter 2024-11-12 12:56:37 +00:00
parent 7b3d1078ec
commit ed0ad98bc4
2 changed files with 26 additions and 1 deletions

View File

@ -821,7 +821,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
// Doctype declarations.
'html' === $token_name ||
// Void elements.
self::is_void( $token_name ) ||
( 'html' === $token_namespace && self::is_void( $token_name ) ) ||
// Special atomic elements.
( 'html' === $token_namespace && in_array( $token_name, array( 'IFRAME', 'NOEMBED', 'NOFRAMES', 'SCRIPT', 'STYLE', 'TEXTAREA', 'TITLE', 'XMP' ), true ) ) ||
// Self-closing elements in foreign content.

View File

@ -561,6 +561,31 @@ class Tests_HtmlApi_WpHtmlProcessor extends WP_UnitTestCase {
$this->assertTrue( $processor->expects_closer() );
}
/**
* Ensures that expects_closer works for void-like elements in foreign content.
*
* For example, `<svg><input>text` creates an `svg:input` that contains a text node.
* This input should not be treated as a void tag and _should_ expect a close tag.
*
* @dataProvider data_void_tags
*
* @ticket 62363
*/
public function test_expects_closer_foreign_content_not_void( string $void_tag ) {
$processor = WP_HTML_Processor::create_fragment( "<svg><{$void_tag}>" );
$this->assertTrue( $processor->next_tag( $void_tag ) );
// Some void-like tags will close the SVG element and be HTML tags.
if ( $processor->get_namespace() === 'svg' ) {
$this->assertSame( array( 'HTML', 'BODY', 'SVG', $void_tag ), $processor->get_breadcrumbs() );
$this->assertTrue( $processor->expects_closer() );
} else {
$this->assertSame( array( 'HTML', 'BODY', $void_tag ), $processor->get_breadcrumbs() );
$this->assertFalse( $processor->expects_closer() );
}
}
/**
* Ensures that self-closing foreign SCRIPT elements are properly found.
*