Make WordPress Core


Ignore:
Timestamp:
04/20/2023 09:11:06 AM (13 months ago)
Author:
Bernhard Reiter
Message:

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.

File:
1 edited

Legend:

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

    r55477 r55662  
    17761776     *
    17771777     * @since 6.2.0
     1778     * @since 6.2.1 Fix: Only create a single update for multiple calls with case-variant attribute names.
    17781779     *
    17791780     * @param string      $name  The attribute name to target.
     
    18681869             *    Result: <div id="new"/>
    18691870             */
    1870             $existing_attribute             = $this->attributes[ $comparable_name ];
    1871             $this->lexical_updates[ $name ] = new WP_HTML_Text_Replacement(
     1871            $existing_attribute = $this->attributes[ $comparable_name ];
     1872            $this->lexical_updates[ $comparable_name ] = new WP_HTML_Text_Replacement(
    18721873                $existing_attribute->start,
    18731874                $existing_attribute->end,
Note: See TracChangeset for help on using the changeset viewer.