Skip to content

Commit 35bbd38

Browse files
committed
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
1 parent b6f6397 commit 35bbd38

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,10 @@ public function next_tag( $query = null ): bool {
557557
return false;
558558
}
559559

560+
if ( isset( $query['tag_name'] ) ) {
561+
$query['tag_name'] = strtoupper( $query['tag_name'] );
562+
}
563+
560564
$needs_class = ( isset( $query['class_name'] ) && is_string( $query['class_name'] ) )
561565
? $query['class_name']
562566
: null;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,4 +882,19 @@ public function test_ensure_form_tag_closer_token_is_reachable() {
882882
$this->assertSame( 'FORM', $processor->get_tag() );
883883
$this->assertTrue( $processor->is_tag_closer() );
884884
}
885+
886+
/**
887+
* Ensure that lowercased tag_name query matches tags case-insensitively.
888+
*
889+
* @group 62427
890+
*/
891+
public function test_next_tag_lowercase_tag_name() {
892+
// The upper case <DIV> is irrelevant but illustrates the case-insentivity.
893+
$processor = WP_HTML_Processor::create_fragment( '<section><DIV>' );
894+
$this->assertTrue( $processor->next_tag( array( 'tag_name' => 'div' ) ) );
895+
896+
// The upper case <RECT> is irrelevant but illustrates the case-insentivity.
897+
$processor = WP_HTML_Processor::create_fragment( '<svg><RECT>' );
898+
$this->assertTrue( $processor->next_tag( array( 'tag_name' => 'rect' ) ) );
899+
}
885900
}

0 commit comments

Comments
 (0)