Make WordPress Core


Ignore:
Timestamp:
09/04/2025 06:30:56 PM (15 months ago)
Author:
jonsurrell
Message:

Editor: Use Unicode escape encoding for "\" characters in block attributes.

Corrects an issue with block attribute encoding where JSON strings ending in the \ character would be misencoded and cause block attributes to be lost.

Client-side block serialization was updated with matching logic in ​https://github.com/WordPress/gutenberg/commit/10453ab3a4e665b8403a0cb466dba64689b4b491.

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

Props jonsurrell, westonruter, mamaduka, dmsnell, shailu25.
Fixes #63917.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r60704 r60708  
    16131613function serialize_block_attributes( $block_attributes ) {
    16141614        $encoded_attributes = wp_json_encode( $block_attributes, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
    1615         $encoded_attributes = preg_replace( '/--/', '\\u002d\\u002d', $encoded_attributes );
    1616         $encoded_attributes = preg_replace( '/</', '\\u003c', $encoded_attributes );
    1617         $encoded_attributes = preg_replace( '/>/', '\\u003e', $encoded_attributes );
    1618         $encoded_attributes = preg_replace( '/&/', '\\u0026', $encoded_attributes );
    1619         // Regex: /\\"/
    1620         $encoded_attributes = preg_replace( '/\\\\"/', '\\u0022', $encoded_attributes );
    1621 
    1622         return $encoded_attributes;
     1615
     1616        return strtr(
     1617                $encoded_attributes,
     1618                array(
     1619                        '\\\\' => '\\u005c',
     1620                        '--'   => '\\u002d\\u002d',
     1621                        '<'    => '\\u003c',
     1622                        '>'    => '\\u003e',
     1623                        '&'    => '\\u0026',
     1624                        '\\"'  => '\\u0022',
     1625                )
     1626        );
    16231627}
    16241628
Note: See TracChangeset for help on using the changeset viewer.