Make WordPress Core


Ignore:
Timestamp:
08/13/2024 10:12:01 PM (20 months ago)
Author:
dmsnell
Message:

HTML API: Only stop on full matches for requested tag name.

An optimization pass on the HTML API left a bug in the matches()
method, whereby it would falsely detect a tag name match if the
found tag were a lexical subset of the requested tag. This occurred
because of the use of substr_compare() without checking that the
outer lengths matched.

This patch resolves the bug by adding the length check.

Developed in https://github.com/wordpress/wordpress-develop/pull/7189
Discussed in https://core.trac.wordpress.org/ticket/61545

Follow-up to [58613].
Props dmsnell, westonruter.
See #61545.

File:
1 edited

Legend:

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

    r58870 r58893  
    40104010
    40114011        // Does the tag name match the requested tag name in a case-insensitive manner?
    4012         if ( isset( $this->sought_tag_name ) && 0 !== substr_compare( $this->html, $this->sought_tag_name, $this->tag_name_starts_at, $this->tag_name_length, true ) ) {
     4012        if (
     4013            isset( $this->sought_tag_name ) &&
     4014            (
     4015                strlen( $this->sought_tag_name ) !== $this->tag_name_length ||
     4016                0 !== substr_compare( $this->html, $this->sought_tag_name, $this->tag_name_starts_at, $this->tag_name_length, true )
     4017            )
     4018        ) {
    40134019            return false;
    40144020        }
Note: See TracChangeset for help on using the changeset viewer.