Make WordPress Core

Changeset 59450


Ignore:
Timestamp:
11/22/2024 12:50:48 PM (2 months ago)
Author:
cbravobernal
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-processor.php

    r59444 r59450  
    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        }
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php

    r59444 r59450  
    11051105
    11061106    /**
     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
     1123    /**
    11071124     * Ensure that lowercased tag_name query matches tags case-insensitively.
    11081125     *
Note: See TracChangeset for help on using the changeset viewer.