Skip to content

Commit

Permalink
HTML API: Use case insensitive tag_name comparison in ::next_tag.
Browse files Browse the repository at this point in the history
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.

Props jonsurrell, dmsnell.
Fixes #62427.


git-svn-id: https://develop.svn.wordpress.org/trunk@59422 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
michalczaplinski committed Nov 19, 2024
1 parent 11e4c7c commit 6c00c00
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ public function next_tag( $query = null ): bool {
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;
Expand Down
15 changes: 15 additions & 0 deletions tests/phpunit/tests/html-api/wpHtmlProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1042,4 +1042,19 @@ public function test_ensure_next_token_method_extensibility( $html, $expected_to

$this->assertEquals( $expected_token_counts, $processor->token_seen_count, 'Snapshot: ' . var_export( $processor->token_seen_count, true ) );
}

/**
* 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' ) ) );
}
}

0 comments on commit 6c00c00

Please sign in to comment.