Skip to content

KSES: Only serialize non-empty attributes. - #14136

Closed
dmsnell wants to merge 1 commit into
WordPress:trunkfrom
dmsnell:kses/only-serialize-actual-attributes
Closed

dmsnell wants to merge 1 commit into
WordPress:trunkfrom
dmsnell:kses/only-serialize-actual-attributes

Conversation

@dmsnell

@dmsnell dmsnell commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Trac ticket: Core-66208

See #8789

When r64255 was added, normalizing all block delimiters inside wp_kses(), if a block contained an empty set of JSON attributes, but the JSON {} was present on the delimiter, then it would be reserialized as [] and misparse later.

This patch fixes that to only print the serialized attributes if there are any, implying a JSON object rather than an array.

Follow-up to: r64255

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props dmsnell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Trac ticket: Core-66208

When r64255 was added, normalizing all block delimiters inside `wp_kses()`, if a block contained an empty set of JSON attributes, but the JSON `{}` was present on the delimiter, then it would be reserialized as `[]` and misparse later.

This patch fixes that to only print the serialized attributes if there are any, implying a JSON object rather than an array.

Follow-up to: r64255

Co-Authored-By: Brad Jorsch <bjorsch@git.wordpress.org>
@dmsnell
dmsnell force-pushed the kses/only-serialize-actual-attributes branch from 167c9f7 to c7844df Compare October 9, 2026 15:03
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

wporg-sync pushed a commit that referenced this pull request Oct 9, 2026
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
@dmsnell

dmsnell commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

Merged in r64258
fd20633

@dmsnell dmsnell closed this Oct 9, 2026
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 9, 2026
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: WordPress/wordpress-develop#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
@dmsnell
dmsnell deleted the kses/only-serialize-actual-attributes branch October 9, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant