Skip to content

Commit 1563d86

Browse files
committed
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
1 parent 849db39 commit 1563d86

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/wp-includes/html-api/class-wp-html-processor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ function ( WP_HTML_Token $token ): void {
464464
* @return static|null The created processor if successful, otherwise null.
465465
*/
466466
public function create_fragment_at_current_node( string $html ) {
467-
if ( $this->get_token_type() !== '#tag' ) {
467+
if ( $this->get_token_type() !== '#tag' || $this->is_tag_closer() ) {
468468
return null;
469469
}
470470

tests/phpunit/tests/html-api/wpHtmlProcessor.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,23 @@ public function test_create_fragment_at_current_node_in_foreign_content_integrat
11031103
$this->assertTrue( $fragment->expects_closer() );
11041104
}
11051105

1106+
/**
1107+
* @ticket 62357
1108+
*/
1109+
public function test_prevent_fragment_creation_on_closers() {
1110+
$processor = WP_HTML_Processor::create_full_parser( '<p></p>' );
1111+
$processor->next_tag( 'P' );
1112+
$processor->next_tag(
1113+
array(
1114+
'tag_name' => 'P',
1115+
'tag_closers' => 'visit',
1116+
)
1117+
);
1118+
$this->assertSame( 'P', $processor->get_tag() );
1119+
$this->assertTrue( $processor->is_tag_closer() );
1120+
$this->assertNull( $processor->create_fragment_at_current_node( '<i>fragment HTML</i>' ) );
1121+
}
1122+
11061123
/**
11071124
* Ensure that lowercased tag_name query matches tags case-insensitively.
11081125
*

0 commit comments

Comments
 (0)