Skip to content

Block Supports: Improve handling of block class name to avoid fatal#12516

Closed
tyxla wants to merge 1 commit into
WordPress:trunkfrom
tyxla:backport/gutenberg-80214
Closed

Block Supports: Improve handling of block class name to avoid fatal#12516
tyxla wants to merge 1 commit into
WordPress:trunkfrom
tyxla:backport/gutenberg-80214

Conversation

@tyxla

@tyxla tyxla commented Jul 14, 2026

Copy link
Copy Markdown
Member

Backport for WordPress/gutenberg#80214
Core trac ticket: https://core.trac.wordpress.org/ticket/65625

What?

Adds defensive guards to block classname attribute handling to avoid fatal errors for corrupted block content.

This is similar to the issue fixed in WordPress/gutenberg#78841.

Why?

Fixes fatal errors that can occur when operating on specific corrupted block content.

While this should be rare in practice because blocks don't normally emit this markup, because the logic is operating on raw block attributes, it needs to be especially defensive about the values that it works with.

How?

Adds additional is_string checks before operating on the className attribute as if it were a string.

Testing instructions

@tyxla tyxla self-assigned this Jul 14, 2026
@github-actions

github-actions Bot commented Jul 14, 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 tyxla, mciampini, isabel_brison.

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

@github-actions

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.

@tellthemachines tellthemachines left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! LGTM; changes match WordPress/gutenberg#80214.

@tellthemachines

Copy link
Copy Markdown
Contributor

I assume you'll commit it @tyxla?

@tyxla

tyxla commented Jul 14, 2026

Copy link
Copy Markdown
Member Author

I assume you'll commit it @tyxla?

Sure thing, will do after the corresponding GB PR lands 👍

pento pushed a commit that referenced this pull request Jul 14, 2026
Add defensive guards to block `className` attribute handling to avoid fatal
errors when operating on corrupted block content.

While rare in practice, because the logic operates on raw block attributes it
needs to be especially defensive about the values it works with. When a block's
`className` attribute is not a string, passing it to `preg_match()` or
`str_contains()` triggers a fatal error on PHP 8+.

In `wp_render_block_style_variation_class_name()`, bail early when `className`
is not a string. In `wp_render_layout_support_flag()`, fall back to an empty
string when `className` is not a string before the `str_contains()` check.

Adds test coverage for both cases.

Developed in: #12516.

Props aduth, mciampini, westonruter, isabel_brison, onemaggie, tyxla.
Fixes #65625.

git-svn-id: https://develop.svn.wordpress.org/trunk@62732 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 62732
GitHub commit: da12379

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Jul 14, 2026
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.

3 participants