Make WordPress Core

Changeset 59464


Ignore:
Timestamp:
11/27/2024 09:55:53 AM (21 months ago)
Author:
cbravobernal
Message:

HTML API: Recognize all uppercase tag names in tag processor.

Fixes a missing "D" in the character list used by strspn to find tag openers, causing tags starting with D to be skipped by the tag processor in some circumstances.

Follow-up to [58613].

Props jonsurrell, santosguillamot, wongjn, cbravobernal.
Fixes #62522.

Location:
trunk
Files:
2 edited

Legend:

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

    r59250 r59464  
    16691669                                 * @see https://html.spec.whatwg.org/#tag-open-state
    16701670                                 */
    1671                                 if ( 1 !== strspn( $html, '!/?abcdefghijklmnopqrstuvwxyzABCEFGHIJKLMNOPQRSTUVWXYZ', $at + 1, 1 ) ) {
     1671                                if ( 1 !== strspn( $html, '!/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', $at + 1, 1 ) ) {
    16721672                                        ++$at;
    16731673                                        continue;
  • trunk/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php

    r58969 r59464  
    29852985                $this->assertNull( $doctype->system_identifier );
    29862986        }
     2987
     2988        /**
     2989         * @ticket 62522
     2990         *
     2991         * @dataProvider data_alphabet_by_characters_lowercase
     2992         */
     2993        public function test_recognizes_lowercase_tag_name( string $char ) {
     2994                /*
     2995                 * The spacing in the HTML string is important to the problematic
     2996                 * codepath in ticket #62522.
     2997                 */
     2998                $html      = " <{$char}> </{$char}>";
     2999                $processor = new WP_HTML_Tag_Processor( $html );
     3000                $this->assertTrue( $processor->next_tag(), "Failed to find open tag in '{$html}'." );
     3001                $this->assertTrue(
     3002                        $processor->next_tag( array( 'tag_closers' => 'visit' ) ),
     3003                        "Failed to find close tag in '{$html}'."
     3004                );
     3005        }
     3006
     3007        /**
     3008         * @ticket 62522
     3009         *
     3010         * @dataProvider data_alphabet_by_characters_uppercase
     3011         */
     3012        public function test_recognizes_uppercase_tag_name( string $char ) {
     3013                /*
     3014                 * The spacing in the HTML string is important to the problematic
     3015                 * codepath in ticket #62522.
     3016                 */
     3017                $html      = " <{$char}> </{$char}>";
     3018                $processor = new WP_HTML_Tag_Processor( $html );
     3019                $this->assertTrue( $processor->next_tag(), "Failed to find open tag in '{$html}'." );
     3020                $this->assertTrue(
     3021                        $processor->next_tag( array( 'tag_closers' => 'visit' ) ),
     3022                        "Failed to find close tag in '{$html}'."
     3023                );
     3024        }
     3025
     3026        /**
     3027         * Data provider.
     3028         *
     3029         * @return Generator<array>
     3030         */
     3031        public static function data_alphabet_by_characters_lowercase() {
     3032                $char = 'a';
     3033                while ( $char <= 'z' ) {
     3034                        yield $char => array( $char );
     3035                        $char = chr( ord( $char ) + 1 );
     3036                }
     3037        }
     3038
     3039        /**
     3040         * Data provider.
     3041         *
     3042         * @return Generator<array>
     3043         */
     3044        public static function data_alphabet_by_characters_uppercase() {
     3045                foreach ( self::data_alphabet_by_characters_lowercase() as $data ) {
     3046                        yield strtoupper( $data[0] ) => array( strtoupper( $data[0] ) );
     3047                }
     3048        }
    29873049}
Note: See TracChangeset for help on using the changeset viewer.