Block Supports: Guard against non-string attribute values to avoid fatal errors (Backport for GB #80501) - #12674
Block Supports: Guard against non-string attribute values to avoid fatal errors (Backport for GB #80501)#12674im3dabasia wants to merge 2 commits into
Conversation
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. |
|
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. |
9d06885 to
0a6edad
Compare
ramonjd
left a comment
There was a problem hiding this comment.
Faithful backport. Nothing to fix in the code. Just needs a track ticket + ticket number in the tests.
Thanks for getting to this!
I reckon it's okay to target the 7.2 milestone for this, what you do think?
|
Thanks for the review!
Yes, this should be fine. If you have a moment, would you mind creating the Trac ticket for this issue? I'm not sure why, but I don't seem to have the |
|
Here it is! |
|
Thanks @ramonjd for the continued efforts to move this PR forward. I've updated the tests to include the Core ticket. I think this is in good shape for us to ship in WordPress 7.2. |
Trac ticket: https://core.trac.wordpress.org/ticket/65774
What?
Backport PR of WordPress/gutenberg#80494
Guards block supports callbacks against non-string (and other wrong-typed) attribute values so they no longer cause fatal
TypeErrors on the front end. (Block support is handled in a this PR.)Why?
block.json/theme.jsontypes aren't enforced at render time, so wrong-typed values from hand-editing, imports, or AI-generated content reach strict PHP ops (explode,preg_match,str_contains,addcslashes,parse_url,array_column,wp_strip_all_tags, array offsets) and fatal in PHP 8+.How?
Following the existing idiom guard with
is_string()/is_array()/is_scalar()before each strict op and treat a wrong-typed value as absent.Testing Instructions
Existing tests should pass
Testing Instructions for Keyboard
N/A — no UI changes.
Use of AI Tools
Claude Code