HTML API: Respect class_name query arg in HTML_Processor::next_tag()

Previously the HTML Process was ignoring the `class_name` argument in
the `next_tag()` query if it existed. This was wrong and would lead to
calling code finding the wrong tag if provided.

This patch adds the class detection code back into `next_tag()` to fix
the bug.

Developed in https://github.com/WordPress/wordpress-develop/pull/6618
Discussed in https://core.trac.wordpress.org/ticket/58517

See #58517.
Follow-up to [56274].
Props: dmsnell, jonsurrell.

Built from https://develop.svn.wordpress.org/trunk@58190


git-svn-id: http://core.svn.wordpress.org/trunk@57653 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dmsnell 2024-05-23 22:45:13 +00:00
parent 3c2e6808c3
commit c3b76697cd
2 changed files with 13 additions and 1 deletions

View File

@ -386,12 +386,20 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
return false;
}
$needs_class = ( isset( $query['class_name'] ) && is_string( $query['class_name'] ) )
? $query['class_name']
: null;
if ( ! ( array_key_exists( 'breadcrumbs', $query ) && is_array( $query['breadcrumbs'] ) ) ) {
while ( $this->step() ) {
if ( '#tag' !== $this->get_token_type() ) {
continue;
}
if ( isset( $needs_class ) && ! $this->has_class( $needs_class ) ) {
continue;
}
if ( ! $this->is_tag_closer() ) {
return true;
}
@ -417,6 +425,10 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
continue;
}
if ( isset( $needs_class ) && ! $this->has_class( $needs_class ) ) {
continue;
}
if ( $this->matches_breadcrumbs( $breadcrumbs ) && 0 === --$match_offset ) {
return true;
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.6-alpha-58189';
$wp_version = '6.6-alpha-58190';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.