From f95abe34df7acdc329d380b23c9168820a767dbb Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Thu, 23 May 2024 22:43:27 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@58190 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/html-api/class-wp-html-processor.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index c76cc192b12a4..3b2efce1c955e 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -386,12 +386,20 @@ public function next_tag( $query = null ) { 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 @@ public function next_tag( $query = null ) { continue; } + if ( isset( $needs_class ) && ! $this->has_class( $needs_class ) ) { + continue; + } + if ( $this->matches_breadcrumbs( $breadcrumbs ) && 0 === --$match_offset ) { return true; }