HTML API: Use case insensitive tag_name comparison in ::next_tag.

The HTML API `::next_tag` method now performs case-insensitive matching when searching for tags by name. For example, searching for 'DIV' will match both '<div>' and '<DIV>' tags.

Reviewed by desrosj.
Merges [59422] to the 6.7 branch.

Props jonsurrell, dmsnell, czapla.
Fixes #62427.

git-svn-id: https://develop.svn.wordpress.org/branches/6.7@59535 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2024-12-18 18:38:58 +00:00
parent b6f639737c
commit 35bbd38934
2 changed files with 19 additions and 0 deletions

View File

@ -557,6 +557,10 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
return false;
}
if ( isset( $query['tag_name'] ) ) {
$query['tag_name'] = strtoupper( $query['tag_name'] );
}
$needs_class = ( isset( $query['class_name'] ) && is_string( $query['class_name'] ) )
? $query['class_name']
: null;

View File

@ -882,4 +882,19 @@ class Tests_HtmlApi_WpHtmlProcessor extends WP_UnitTestCase {
$this->assertSame( 'FORM', $processor->get_tag() );
$this->assertTrue( $processor->is_tag_closer() );
}
/**
* Ensure that lowercased tag_name query matches tags case-insensitively.
*
* @group 62427
*/
public function test_next_tag_lowercase_tag_name() {
// The upper case <DIV> is irrelevant but illustrates the case-insentivity.
$processor = WP_HTML_Processor::create_fragment( '<section><DIV>' );
$this->assertTrue( $processor->next_tag( array( 'tag_name' => 'div' ) ) );
// The upper case <RECT> is irrelevant but illustrates the case-insentivity.
$processor = WP_HTML_Processor::create_fragment( '<svg><RECT>' );
$this->assertTrue( $processor->next_tag( array( 'tag_name' => 'rect' ) ) );
}
}