Commit 3310b5ccad for wordpress.org

commit 3310b5ccad24f88b53396fbd01bdc4224d9fc5b2
Author: dmsnell <dmsnell@git.wordpress.org>
Date:   Fri Oct 9 15:20:52 2026 +0000

    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.

    Built from https://develop.svn.wordpress.org/trunk@64258


    git-svn-id: http://core.svn.wordpress.org/trunk@63409 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/kses.php b/wp-includes/kses.php
index 2dddd0f04b..aba6e0d2a5 100644
--- a/wp-includes/kses.php
+++ b/wp-includes/kses.php
@@ -1705,7 +1705,7 @@ function wp_sanitize_html_kses( $content, $allowed_html, $allowed_protocols = ar
 							// Fully normalize all block delimiters: name, whitespace, attributes, flags.
 							if ( WP_Block_Processor::CLOSER === $block_processor->get_delimiter_type() ) {
 								$text = " /wp:{$implicit_block_type} ";
-							} elseif ( isset( $attributes ) ) {
+							} elseif ( ! empty( $attributes ) ) {
 								$serialized_attributes = serialize_block_attributes( $attributes );

 								$text = " wp:{$implicit_block_type} {$serialized_attributes} {$voider}";
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 37b898fc21..fc2ade1ca8 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.2-alpha-64257';
+$wp_version = '7.2-alpha-64258';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.