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 39196499fa..4bdb75fcac 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -464,7 +464,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * @return static|null The created processor if successful, otherwise null. */ public function create_fragment_at_current_node( string $html ) { - if ( $this->get_token_type() !== '#tag' ) { + if ( $this->get_token_type() !== '#tag' || $this->is_tag_closer() ) { return null; } diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessor.php b/tests/phpunit/tests/html-api/wpHtmlProcessor.php index a19af13c78..f80260cbc1 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessor.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessor.php @@ -1103,6 +1103,23 @@ class Tests_HtmlApi_WpHtmlProcessor extends WP_UnitTestCase { $this->assertTrue( $fragment->expects_closer() ); } + /** + * @ticket 62357 + */ + public function test_prevent_fragment_creation_on_closers() { + $processor = WP_HTML_Processor::create_full_parser( '
' ); + $processor->next_tag( 'P' ); + $processor->next_tag( + array( + 'tag_name' => 'P', + 'tag_closers' => 'visit', + ) + ); + $this->assertSame( 'P', $processor->get_tag() ); + $this->assertTrue( $processor->is_tag_closer() ); + $this->assertNull( $processor->create_fragment_at_current_node( 'fragment HTML' ) ); + } + /** * Ensure that lowercased tag_name query matches tags case-insensitively. *