Skip to content

Commit

Permalink
HTML API: Recognize all uppercase tag names in tag processor.
Browse files Browse the repository at this point in the history
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.


git-svn-id: https://develop.svn.wordpress.org/trunk@59464 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
cbravobernal committed Nov 27, 2024
1 parent 6ed2409 commit 9840f03
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/wp-includes/html-api/class-wp-html-tag-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ private function parse_next_tag(): bool {
*
* @see https://html.spec.whatwg.org/#tag-open-state
*/
if ( 1 !== strspn( $html, '!/?abcdefghijklmnopqrstuvwxyzABCEFGHIJKLMNOPQRSTUVWXYZ', $at + 1, 1 ) ) {
if ( 1 !== strspn( $html, '!/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', $at + 1, 1 ) ) {
++$at;
continue;
}
Expand Down
62 changes: 62 additions & 0 deletions tests/phpunit/tests/html-api/wpHtmlTagProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2984,4 +2984,66 @@ public function test_doctype_doc_name() {
$this->assertNull( $doctype->public_identifier );
$this->assertNull( $doctype->system_identifier );
}

/**
* @ticket 62522
*
* @dataProvider data_alphabet_by_characters_lowercase
*/
public function test_recognizes_lowercase_tag_name( string $char ) {
/*
* The spacing in the HTML string is important to the problematic
* codepath in ticket #62522.
*/
$html = " <{$char}> </{$char}>";
$processor = new WP_HTML_Tag_Processor( $html );
$this->assertTrue( $processor->next_tag(), "Failed to find open tag in '{$html}'." );
$this->assertTrue(
$processor->next_tag( array( 'tag_closers' => 'visit' ) ),
"Failed to find close tag in '{$html}'."
);
}

/**
* @ticket 62522
*
* @dataProvider data_alphabet_by_characters_uppercase
*/
public function test_recognizes_uppercase_tag_name( string $char ) {
/*
* The spacing in the HTML string is important to the problematic
* codepath in ticket #62522.
*/
$html = " <{$char}> </{$char}>";
$processor = new WP_HTML_Tag_Processor( $html );
$this->assertTrue( $processor->next_tag(), "Failed to find open tag in '{$html}'." );
$this->assertTrue(
$processor->next_tag( array( 'tag_closers' => 'visit' ) ),
"Failed to find close tag in '{$html}'."
);
}

/**
* Data provider.
*
* @return Generator<array>
*/
public static function data_alphabet_by_characters_lowercase() {
$char = 'a';
while ( $char <= 'z' ) {
yield $char => array( $char );
$char = chr( ord( $char ) + 1 );
}
}

/**
* Data provider.
*
* @return Generator<array>
*/
public static function data_alphabet_by_characters_uppercase() {
foreach ( self::data_alphabet_by_characters_lowercase() as $data ) {
yield strtoupper( $data[0] ) => array( strtoupper( $data[0] ) );
}
}
}

0 comments on commit 9840f03

Please sign in to comment.