HTML API: Ensure attribute updates happen only once for case variants.

When setting a new value for an attribute multiple times and providing
multiple case variations of the attribute name the Tag Processor has
been appending multiple copies of the attribute into the updated HTML.

This means that only the first attribute set determines the value in
the final output, plus the output will //appear// wrong.

In this patch we're adding a test to catch the situation and resolving it
by using the appropriate comparable attribute name as a key for storing
the updates as we go. Previously we stored updates to the attribute by
its given `$name`, but when a new update of the same name with a
case variant was queued, it would not override the previously-enqueued
value as it out to have.

Props dmsnell, zieladam.
Merges [55659] to the 6.2 branch.
Fixes #58146.
Built from https://develop.svn.wordpress.org/branches/6.2@55662


git-svn-id: http://core.svn.wordpress.org/branches/6.2@55174 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Bernhard Reiter 2023-04-20 09:13:23 +00:00
parent b838393386
commit 484b3840bd
2 changed files with 4 additions and 3 deletions

View File

@ -1775,6 +1775,7 @@ class WP_HTML_Tag_Processor {
* For string attributes, the value is escaped using the `esc_attr` function.
*
* @since 6.2.0
* @since 6.2.1 Fix: Only create a single update for multiple calls with case-variant attribute names.
*
* @param string $name The attribute name to target.
* @param string|bool $value The new attribute value.
@ -1867,8 +1868,8 @@ class WP_HTML_Tag_Processor {
*
* Result: <div id="new"/>
*/
$existing_attribute = $this->attributes[ $comparable_name ];
$this->lexical_updates[ $name ] = new WP_HTML_Text_Replacement(
$existing_attribute = $this->attributes[ $comparable_name ];
$this->lexical_updates[ $comparable_name ] = new WP_HTML_Text_Replacement(
$existing_attribute->start,
$existing_attribute->end,
$updated_attribute

View File

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