Skip to content

Commit ed0ad98

Browse files
committed
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
1 parent 7b3d107 commit ed0ad98

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ public function expects_closer( ?WP_HTML_Token $node = null ): ?bool {
821821
// Doctype declarations.
822822
'html' === $token_name ||
823823
// Void elements.
824-
self::is_void( $token_name ) ||
824+
( 'html' === $token_namespace && self::is_void( $token_name ) ) ||
825825
// Special atomic elements.
826826
( 'html' === $token_namespace && in_array( $token_name, array( 'IFRAME', 'NOEMBED', 'NOFRAMES', 'SCRIPT', 'STYLE', 'TEXTAREA', 'TITLE', 'XMP' ), true ) ) ||
827827
// Self-closing elements in foreign content.

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,31 @@ public function test_expects_closer_foreign_content_self_closing() {
561561
$this->assertTrue( $processor->expects_closer() );
562562
}
563563

564+
/**
565+
* Ensures that expects_closer works for void-like elements in foreign content.
566+
*
567+
* For example, `<svg><input>text` creates an `svg:input` that contains a text node.
568+
* This input should not be treated as a void tag and _should_ expect a close tag.
569+
*
570+
* @dataProvider data_void_tags
571+
*
572+
* @ticket 62363
573+
*/
574+
public function test_expects_closer_foreign_content_not_void( string $void_tag ) {
575+
$processor = WP_HTML_Processor::create_fragment( "<svg><{$void_tag}>" );
576+
577+
$this->assertTrue( $processor->next_tag( $void_tag ) );
578+
579+
// Some void-like tags will close the SVG element and be HTML tags.
580+
if ( $processor->get_namespace() === 'svg' ) {
581+
$this->assertSame( array( 'HTML', 'BODY', 'SVG', $void_tag ), $processor->get_breadcrumbs() );
582+
$this->assertTrue( $processor->expects_closer() );
583+
} else {
584+
$this->assertSame( array( 'HTML', 'BODY', $void_tag ), $processor->get_breadcrumbs() );
585+
$this->assertFalse( $processor->expects_closer() );
586+
}
587+
}
588+
564589
/**
565590
* Ensures that self-closing foreign SCRIPT elements are properly found.
566591
*

0 commit comments

Comments
 (0)