Block Supports: Improve handling of block class name to avoid fatal#12516
Block Supports: Improve handling of block class name to avoid fatal#12516tyxla wants to merge 1 commit into
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
tellthemachines
left a comment
There was a problem hiding this comment.
Thanks for the PR! LGTM; changes match WordPress/gutenberg#80214.
|
I assume you'll commit it @tyxla? |
Sure thing, will do after the corresponding GB PR lands 👍 |
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
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_stringchecks before operating on theclassNameattribute as if it were a string.Testing instructions