Make WordPress Core


Ignore:
Timestamp:
06/11/2026 10:17:13 PM (3 months ago)
Author:
dmsnell
Message:

HTML API: preserve adjusted foreign attributes on serialization.

Discovered during fuzz-testing of the HTML API. Adjusted foreign attributes, such as xlink:href, were being normalized with a space instead of a colon through ::serialize_token(). This led to the creation of two attributes on output instead of the proper singular attribute.

This patch corrects the issue by ensuring that the attribute namespace and name are separated by a colon when serializing.

Developed in: https://github.com/WordPress/wordpress-develop/pull/12140
Discussed in: https://core.trac.wordpress.org/ticket/65372

Props jonsurrell.
See #65372.

File:
1 edited

Legend:

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

    r62439 r62492  
    14291429                        $qualified_attribute_name = str_replace( "\x00", "\u{FFFD}", $qualified_attribute_name );
    14301430                        $qualified_attribute_name = wp_scrub_utf8( $qualified_attribute_name );
     1431                        /**
     1432                         * Spaces only appear via the foreign attribute adjustment table.
     1433                         * @see WP_HTML_Tag_Processor::get_qualified_attribute_name()
     1434                         */
     1435                        $serialized_attribute_name = str_replace( ' ', ':', $qualified_attribute_name );
    14311436                        if ( isset( $seen_attribute_names[ $qualified_attribute_name ] ) ) {
    14321437                                continue;
     
    14371442                        if (
    14381443                                $previous_attribute_was_true &&
    1439                                 isset( $qualified_attribute_name[0] ) &&
    1440                                 '=' === $qualified_attribute_name[0]
     1444                                isset( $serialized_attribute_name[0] ) &&
     1445                                '=' === $serialized_attribute_name[0]
    14411446                        ) {
    14421447                                $html .= '=""';
    14431448                        }
    14441449
    1445                         $html .= " {$qualified_attribute_name}";
     1450                        $html .= " {$serialized_attribute_name}";
    14461451                        $value = $this->get_attribute( $attribute_name );
    14471452
Note: See TracChangeset for help on using the changeset viewer.