Skip to content

Commit fd20633

Browse files
committed
KSES: Only serialize non-empty block JSON attributes.
In r64255 `wp_kses()` completely reserializes every block delimiter, including any JSON attributes. Unfortunately, if a delimiter contained no JSON attributes, but still presented an empty JSON map, these attributes would be re-serialized as an empty list due to the ambiguity of empty PHP arrays. This led to blocks no-longer parsing as blocks. wp_kses( '<!-- wp:block {} -->' ) // turns into `<!-- wp:block [] -->` This patch checks if any attributes exist before serializing them into the block delimiter. There is a pre-existing version of this problem in WordPress for block JSON attributes whose value is an empty map, but r64255 did not change how those are modified through `wp_kses()`. Developed in: #14136 Discussed in: https://core.trac.wordpress.org/ticket/66208 Follow-up to: r64255. Props bjorsch, dmsnell. See #66208. git-svn-id: https://develop.svn.wordpress.org/trunk@64258 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 3591842 commit fd20633

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎src/wp-includes/kses.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ public function sanitize() {
17051705
// Fully normalize all block delimiters: name, whitespace, attributes, flags.
17061706
if ( WP_Block_Processor::CLOSER === $block_processor->get_delimiter_type() ) {
17071707
$text = " /wp:{$implicit_block_type} ";
1708-
} elseif ( isset( $attributes ) ) {
1708+
} elseif ( ! empty( $attributes ) ) {
17091709
$serialized_attributes = serialize_block_attributes( $attributes );
17101710

17111711
$text = " wp:{$implicit_block_type} {$serialized_attributes} {$voider}";

0 commit comments

Comments
 (0)