Skip to content

Commit

Permalink
HTML API: Prevent fragment creation on close tag.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cbravobernal committed Nov 22, 2024
1 parent 849db39 commit 1563d86
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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 @@ -464,7 +464,7 @@ function ( WP_HTML_Token $token ): void {
* @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;
}

Expand Down
17 changes: 17 additions & 0 deletions tests/phpunit/tests/html-api/wpHtmlProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,23 @@ public function test_create_fragment_at_current_node_in_foreign_content_integrat
$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.
*
Expand Down

0 comments on commit 1563d86

Please sign in to comment.