Skip to content

Commit dfe773a

Browse files
committed
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]. Reviewed by desrosj. Merges [59464] to the 6.7 branch. Props jonsurrell, santosguillamot, wongjn, cbravobernal. Fixes #62522. git-svn-id: https://develop.svn.wordpress.org/branches/6.7@59537 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 35bbd38 commit dfe773a

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ private function parse_next_tag(): bool {
16681668
*
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;
16741674
}

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2984,4 +2984,66 @@ public function test_doctype_doc_name() {
29842984
$this->assertNull( $doctype->public_identifier );
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
}

0 commit comments

Comments
 (0)