Make WordPress Core

Opened 7 hours ago

Last modified 2 hours ago

#62427 assigned defect (bug)

HTML API: Next tag tag name query is case sensitive

Reported by: jonsurrell's profile jonsurrell Owned by: jonsurrell's profile jonsurrell
Milestone: 6.7.1 Priority: normal
Severity: normal Version: 6.6
Component: HTML API Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

The HTML API ::next_tag method accepts a tag_name query. The tag name matching should be case-insensitive. Tag names are generally UPPERCASE in the processors, a lower or mixed case name doesn't make much sense.

<?php
// This is OK
$processor = WP_HTML_Processor::create_fragment( '<DIV>' );
assert( $processor->next_tag( 'div' ) );

// This is OK
$processor = WP_HTML_Processor::create_fragment( '<DIV>' );
assert( $processor->next_tag( array( 'breadcrumbs' => array( 'div' ) ) ) );

// This does not work but should
$processor = WP_HTML_Processor::create_fragment( '<DIV>' );
assert( $processor->next_tag( array( 'tag_name' => 'div' ) ) ); // AssertionError!

This is also supported in the tag processor case-insensitively:

<?php
$processor = new WP_HTML_Tag_Processor( '<section><DIV>' );
assert( $processor->next_tag( array( 'tag_name' => 'div' ) ) );
$processor->get_tag(); // "DIV"

Change History (3)

This ticket was mentioned in PR #7754 on WordPress/wordpress-develop by @jonsurrell.


7 hours ago
#1

  • Keywords has-patch has-unit-tests added

Trac ticket: https://core.trac.wordpress.org/ticket/62427

The HTML API ::next_tag method accepts a tag_name query. The tag name matching should be case-insensitive. Tag names are generally UPPERCASE in the processors, a lower or mixed case name doesn't make much sense.

// This is OK
$processor = WP_HTML_Processor::create_fragment( '<DIV>' );
assert( $processor->next_tag( 'div' ) );

// This is OK
$processor = WP_HTML_Processor::create_fragment( '<DIV>' );
assert( $processor->next_tag( array( 'breadcrumbs' => array( 'div' ) ) ) );

// This does not work but should
$processor = WP_HTML_Processor::create_fragment( '<DIV>' );
assert( $processor->next_tag( array( 'tag_name' => 'div' ) ) ); // AssertionError!

This is also supported in the tag processor case-insensitively:

$processor = new WP_HTML_Tag_Processor( '<section><DIV>' );
assert( $processor->next_tag( array( 'tag_name' => 'div' ) ) );
$processor->get_tag(); // "DIV"

@dmsnell commented on PR #7754:


4 hours ago
#2

Did we originally do this intentionally ASCII case-sensitively, and if so, why?

@jonsurrell commented on PR #7754:


2 hours ago
#3

As far as I can tell this was an oversight. I can't think of a reason _to_ match this case-sensitively.

I suspect this was not noticed because the shorthand exists for the next tag with a tag name in the HTML Processor: next_tag( 'div' ).

Under the hood that uses next_tag( array( 'breadcrumbs' => array( 'div' ) ) ):

https://github.com/WordPress/wordpress-develop/blob/e9dfa8c34c74cb51da93ae4b4e61c1df0378b3d7/src/wp-includes/html-api/class-wp-html-processor.php#L547-L549

And _that_ is handled correctly by the matches_breadcrumbs function:

https://github.com/WordPress/wordpress-develop/blob/e9dfa8c34c74cb51da93ae4b4e61c1df0378b3d7/src/wp-includes/html-api/class-wp-html-processor.php#L776

(I had included a change in this patch to change the shorthand implementation to use tag_name instead of breadcrumbs, but removed that as out-of-scope for a bugfix.)

Note: See TracTickets for help on using tickets.