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 4bde9e1c099c8..6b0879cde892f 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -431,7 +431,7 @@ public function next_token() { $found_a_token = parent::next_token(); if ( '#tag' === $this->get_token_type() ) { - $this->step( self::REPROCESS_CURRENT_NODE ); + $this->step( self::PROCESS_CURRENT_NODE ); } return $found_a_token; @@ -513,7 +513,7 @@ public function step( $node_to_process = self::PROCESS_NEXT_NODE ) { return false; } - if ( self::PROCESS_NEXT_NODE === $node_to_process ) { + if ( self::REPROCESS_CURRENT_NODE !== $node_to_process ) { /* * Void elements still hop onto the stack of open elements even though * there's no corresponding closing tag. This is important for managing @@ -532,7 +532,9 @@ public function step( $node_to_process = self::PROCESS_NEXT_NODE ) { if ( $top_node && self::is_void( $top_node->node_name ) ) { $this->state->stack_of_open_elements->pop(); } + } + if ( self::PROCESS_NEXT_NODE === $node_to_process ) { while ( parent::next_token() && '#tag' !== $this->get_token_type() ) { continue; } @@ -1781,6 +1783,15 @@ public static function is_void( $tag_name ) { */ const REPROCESS_CURRENT_NODE = 'reprocess-current-node'; + /** + * Indicates that the current HTML token should be processed without advancing the parser. + * + * @since 6.5.0 + * + * @var string + */ + const PROCESS_CURRENT_NODE = 'process-current-node'; + /** * Indicates that the parser encountered unsupported markup and has bailed. * diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessor.php b/tests/phpunit/tests/html-api/wpHtmlProcessor.php index 109f384e25e3c..60d368efae1cc 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessor.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessor.php @@ -188,6 +188,59 @@ public function test_cannot_nest_void_tags( $tag_name ) { ); } + /** + * Ensure non-nesting tags do not nest when processing tokens. + * + * @ticket 60382 + * + * @dataProvider data_void_tags + * + * @param string $tag_name Name of void tag under test. + */ + public function test_cannot_nest_void_tags_next_token( $tag_name ) { + $processor = WP_HTML_Processor::create_fragment( "<{$tag_name}>