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
2 changes: 1 addition & 1 deletion src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ public function expects_closer( ?WP_HTML_Token $node = null ): ?bool {
// 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.
Expand Down
25 changes: 25 additions & 0 deletions tests/phpunit/tests/html-api/wpHtmlProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,31 @@ public function test_expects_closer_foreign_content_self_closing() {
$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.
*
Expand Down
Loading