Make WordPress Core

Changeset 64258


Ignore:
Timestamp:
10/09/2026 03:19:24 PM (6 weeks ago)
Author:
dmsnell
Message:

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: ​https://github.com/WordPress/wordpress-develop/pull/14136
Discussed in: https://core.trac.wordpress.org/ticket/66208

Follow-up to: r64255.

Props bjorsch, dmsnell.
See #66208.

File:
1 edited

Legend:

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

    r64255 r64258  
    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
Note: See TracChangeset for help on using the changeset viewer.