Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,7 @@ function make_after_block_visitor( $hooked_blocks, $context, $callback = 'insert
* @return string Serialized attributes.
*/
function serialize_block_attributes( $block_attributes ) {
$encoded_attributes = wp_json_encode( $block_attributes, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
$encoded_attributes = wp_json_encode( (object) $block_attributes, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
$encoded_attributes = preg_replace( '/--/', '\\u002d\\u002d', $encoded_attributes );
$encoded_attributes = preg_replace( '/</', '\\u003c', $encoded_attributes );
$encoded_attributes = preg_replace( '/>/', '\\u003e', $encoded_attributes );
Expand Down
12 changes: 12 additions & 0 deletions tests/phpunit/tests/blocks/serialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ public function data_serialize_identity_from_parsed() {

// Block with attribute values that should not be escaped.
array( '<!-- wp:attributes {"key":"€1.00 / 3 for €2.00"} /-->' ),

// Block with attribute values that have empty keys.
array( '<!-- wp:attributes {"key":{},"nested":{"key2":{}}} /-->' ),

// Block with attribute values that have array keys.
array( '<!-- wp:attributes {"key":[],"nested":{"key2":[]}} /-->' ),

// Block with attribute values that have string numeric keys.
array( '<!-- wp:attributes {"1":"one","2":"two"} /-->' ),

// Block with attribute values that have numeric keys.
array( '<!-- wp:attributes {1:"one",2:"two"} /-->' ),
);
}

Expand Down
Loading