HTML API: Prevent fragment creation on close tag.

Prevent fragments from being created at tag closers.

Follow-up to [59444].

Props jonsurrell, bernhard-reiter.
Fixes #62357.


git-svn-id: https://develop.svn.wordpress.org/trunk@59450 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Carlos Bravo 2024-11-22 12:50:48 +00:00
parent 849db39fc7
commit 1563d8622d
2 changed files with 18 additions and 1 deletions

View File

@ -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;
}

View File

@ -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( '<p></p>' );
$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( '<i>fragment HTML</i>' ) );
}
/**
* Ensure that lowercased tag_name query matches tags case-insensitively.
*