diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php
index 3820fe0277..415ff23eea 100644
--- a/src/wp-includes/html-api/class-wp-html-processor.php
+++ b/src/wp-includes/html-api/class-wp-html-processor.php
@@ -786,13 +786,15 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
* or `null` if not matched on any token.
*/
public function expects_closer( WP_HTML_Token $node = null ): ?bool {
- $token_name = $node->node_name ?? $this->get_token_name();
- $token_namespace = $node->namespace ?? $this->get_namespace();
+ $token_name = $node->node_name ?? $this->get_token_name();
if ( ! isset( $token_name ) ) {
return null;
}
+ $token_namespace = $node->namespace ?? $this->get_namespace();
+ $token_has_self_closing = $node->has_self_closing_flag ?? $this->has_self_closing_flag();
+
return ! (
// Comments, text nodes, and other atomic tokens.
'#' === $token_name[0] ||
@@ -803,7 +805,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
// 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.
- ( isset( $node ) && 'html' !== $node->namespace && $node->has_self_closing_flag )
+ ( 'html' !== $token_namespace && $token_has_self_closing )
);
}
diff --git a/src/wp-includes/html-api/class-wp-html-tag-processor.php b/src/wp-includes/html-api/class-wp-html-tag-processor.php
index fb21c15d1d..95216b08a1 100644
--- a/src/wp-includes/html-api/class-wp-html-tag-processor.php
+++ b/src/wp-includes/html-api/class-wp-html-tag-processor.php
@@ -2921,7 +2921,7 @@ class WP_HTML_Tag_Processor {
return null;
}
- $namespace = $this->get_namespace();
+ $namespace = $this->get_namespace();
$lower_name = strtolower( $attribute_name );
if ( 'math' === $namespace && 'definitionurl' === $lower_name ) {
diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessor.php b/tests/phpunit/tests/html-api/wpHtmlProcessor.php
index 68c60a1ff8..2b56cefedc 100644
--- a/tests/phpunit/tests/html-api/wpHtmlProcessor.php
+++ b/tests/phpunit/tests/html-api/wpHtmlProcessor.php
@@ -503,4 +503,22 @@ class Tests_HtmlApi_WpHtmlProcessor extends WP_UnitTestCase {
$subclass_processor = call_user_func( array( get_class( $subclass_instance ), 'create_fragment' ), '' );
$this->assertInstanceOf( get_class( $subclass_instance ), $subclass_processor, '::create_fragment did not return subclass instance.' );
}
+
+ /**
+ * Ensures that self-closing elements in foreign content properly report
+ * that they expect no closer.
+ *
+ * @ticket 61576
+ */
+ public function test_expects_closer_foreign_content_self_closing() {
+ $processor = WP_HTML_Processor::create_fragment( '