Make WordPress Core

Changeset 63179


Ignore:
Timestamp:
08/11/2026 01:25:23 PM (3 months ago)
Author:
jonsurrell
Message:

HTML API: Recognize form feed in RCDATA and RAWTEXT tag closers.

Form feeds after closing tag names were not recognized, causing complete elements to appear incomplete.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/12936.

Props jonsurrell, westonruter.
See #65372.

Location:
trunk
Files:
2 edited

Legend:

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

    r63178 r63179  
    14761476                         */
    14771477                        $c = $html[ $at ];
    1478                         if ( ' ' !== $c && "\t" !== $c && "\r" !== $c && "\n" !== $c && '/' !== $c && '>' !== $c ) {
     1478                        if ( ' ' !== $c && "\t" !== $c && "\f" !== $c && "\r" !== $c && "\n" !== $c && '/' !== $c && '>' !== $c ) {
    14791479                                continue;
    14801480                        }
  • trunk/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php

    r62960 r63179  
    23682368                        yield 'Script tag double-escaped with <script\f'      => array( "<script><!--<script\f</script>", false );
    23692369                        yield 'Script tag double-escaped with <script\r'      => array( "<script><!--<script\r</script>", false );
     2370        }
     2371
     2372        /**
     2373         * Ensures that tag-name-terminating characters close RCDATA and RAWTEXT elements.
     2374         *
     2375         * @ticket 65372
     2376         *
     2377         * @dataProvider data_rcdata_and_rawtext_tag_name_terminators
     2378         *
     2379         * @param non-falsy-string $tag_name            The RCDATA or RAWTEXT tag name.
     2380         * @param non-falsy-string $tag_name_terminator The tag-name-terminating character.
     2381         */
     2382        public function test_rcdata_and_rawtext_end_tags_accept_tag_name_terminators( string $tag_name, string $tag_name_terminator ): void {
     2383                $end_tag_closer = '>' === $tag_name_terminator ? '' : '>';
     2384                $processor      = new WP_HTML_Tag_Processor( "<{$tag_name}>content</{$tag_name}{$tag_name_terminator}{$end_tag_closer}<div>" );
     2385
     2386                $this->assertTrue( $processor->next_token(), "Expected to find complete {$tag_name} tag." );
     2387                $this->assertSame( strtoupper( $tag_name ), $processor->get_tag() );
     2388                $this->assertSame( 'content', $processor->get_modifiable_text() );
     2389                $this->assertTrue( $processor->next_tag( 'DIV' ), "Expected to find DIV after the {$tag_name} element." );
     2390        }
     2391
     2392        /**
     2393         * Provides every RCDATA and RAWTEXT tag with every tag-name-terminating character.
     2394         *
     2395         * @return Generator<non-falsy-string, array{non-falsy-string, non-falsy-string}> Test cases.
     2396         */
     2397        public static function data_rcdata_and_rawtext_tag_name_terminators(): Generator {
     2398                foreach ( array( 'IFRAME', 'NOEMBED', 'NOFRAMES', 'STYLE', 'XMP', 'TEXTAREA', 'TITLE' ) as $tag_name ) {
     2399                        foreach ( self::data_tag_name_terminators() as $terminator_name => $terminator_data ) {
     2400                                yield "{$tag_name} + {$terminator_name}" => array( strtolower( $tag_name ), $terminator_data[0] );
     2401                        }
     2402                }
     2403        }
     2404
     2405        /**
     2406         * Provides tag-name-terminating characters.
     2407         *
     2408         * @return Generator<non-falsy-string, array{non-falsy-string}> Test cases.
     2409         */
     2410        public static function data_tag_name_terminators(): Generator {
     2411                yield 'SPACE'             => array( ' ' );
     2412                yield 'TAB'               => array( "\t" );
     2413                yield 'LINE FEED'         => array( "\n" );
     2414                yield 'FORM FEED'         => array( "\f" );
     2415                yield 'CARRIAGE RETURN'   => array( "\r" );
     2416                yield 'SOLIDUS'           => array( '/' );
     2417                yield 'GREATER-THAN SIGN' => array( '>' );
    23702418        }
    23712419
Note: See TracChangeset for help on using the changeset viewer.