Make WordPress Core


Ignore:
Timestamp:
08/26/2021 07:09:16 PM (3 years ago)
Author:
desrosj
Message:

Editor: Ensure block attribute serialization in PHP matches the JavaScript equivalent.

The serializeAttributes() function in JavaScript uses JSON.stringify, which does not encode slashes and unicode characters by default. This resulted in the PHP serialization through json_encode() producing different results.

This also switches from json_encode() to wp_json_encode() to prevent failures when any non UTF-8 characters are included.

Props kevinfodness, SergeyBiryukov, timothyblynjacobs.
Fixes #53936.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/serialize.php

    r51491 r51674  
    4848            // Block with attribute values that may conflict with HTML comment.
    4949            array( '<!-- wp:attributes {"key":"\\u002d\\u002d\\u003c\\u003e\\u0026\\u0022"} /-->' ),
     50
     51            // Block with attribute values that should not be escaped.
     52            array( '<!-- wp:attributes {"key":"€1.00 / 3 for €2.00"} /-->' ),
    5053        );
    5154    }
Note: See TracChangeset for help on using the changeset viewer.