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.

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


git-svn-id: http://core.svn.wordpress.org/trunk@58289 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dmsnell 2024-08-13 22:14:16 +00:00
parent 9aaf4b144a
commit f957219299
2 changed files with 8 additions and 2 deletions

View File

@ -4009,7 +4009,13 @@ class WP_HTML_Tag_Processor {
} }
// Does the tag name match the requested tag name in a case-insensitive manner? // Does the tag name match the requested tag name in a case-insensitive manner?
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 ) ) { if (
isset( $this->sought_tag_name ) &&
(
strlen( $this->sought_tag_name ) !== $this->tag_name_length ||
0 !== substr_compare( $this->html, $this->sought_tag_name, $this->tag_name_starts_at, $this->tag_name_length, true )
)
) {
return false; return false;
} }

View File

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