Make WordPress Core

Changeset 58190


Ignore:
Timestamp:
05/23/2024 10:43:27 PM (2 months ago)
Author:
dmsnell
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-processor.php

    r57806 r58190  
    387387        }
    388388
     389        $needs_class = ( isset( $query['class_name'] ) && is_string( $query['class_name'] ) )
     390            ? $query['class_name']
     391            : null;
     392
    389393        if ( ! ( array_key_exists( 'breadcrumbs', $query ) && is_array( $query['breadcrumbs'] ) ) ) {
    390394            while ( $this->step() ) {
    391395                if ( '#tag' !== $this->get_token_type() ) {
     396                    continue;
     397                }
     398
     399                if ( isset( $needs_class ) && ! $this->has_class( $needs_class ) ) {
    392400                    continue;
    393401                }
     
    415423        while ( $match_offset > 0 && $this->step() ) {
    416424            if ( '#tag' !== $this->get_token_type() ) {
     425                continue;
     426            }
     427
     428            if ( isset( $needs_class ) && ! $this->has_class( $needs_class ) ) {
    417429                continue;
    418430            }
Note: See TracChangeset for help on using the changeset viewer.