Make WordPress Core


Ignore:
Timestamp:
12/03/2025 05:25:34 PM (8 hours ago)
Author:
jonsurrell
Message:

HTML API: Ensure correct encoding of modified class names.

Some class names with HTML character references could be mishandled, for example:

  • Failure to remove an existing class like & with ::remove_class( '&' )
  • Double-encoding of an existing class like & after a modification, becoming &

The second case manifested after double-encoding prevention was removed from ::set_attribute() in [60919].

Developed in https://github.com/WordPress/wordpress-develop/pull/10591.

Props jonsurrell, dmsnell.
Fixes #64340.

File:
1 edited

Legend:

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

    r61003 r61346  
    23432343
    23442344        if ( false === $existing_class && isset( $this->attributes['class'] ) ) {
    2345             $existing_class = substr(
    2346                 $this->html,
    2347                 $this->attributes['class']->value_starts_at,
    2348                 $this->attributes['class']->value_length
     2345            $existing_class = WP_HTML_Decoder::decode_attribute(
     2346                substr(
     2347                    $this->html,
     2348                    $this->attributes['class']->value_starts_at,
     2349                    $this->attributes['class']->value_length
     2350                )
    23492351            );
    23502352        }
Note: See TracChangeset for help on using the changeset viewer.