Editor: Handle nested array block gap values properly - #12604
Conversation
Guard against non-scalar (nested array) `blockGap` values in `wp_sanitize_block_gap_value()` before passing them to `preg_match()`, which requires a string subject. A malformed axial gap value such as `blockGap.top` = `["1rem"]` previously triggered an uncaught `TypeError`, breaking front-end rendering and REST API responses. Non-scalar values are now treated as invalid and set to `null`, and scalar values are cast to string for the regex check. Includes a direct unit test for `wp_sanitize_block_gap_value()` and a data-provider case covering rendering with a malformed axial block gap. Ports WordPress/gutenberg#80464 to core. Props tyxla. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Fixes #65667.
|
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. |
Guard against non-scalar (nested array) `blockGap` values in `wp_sanitize_block_gap_value()` before passing them to `preg_match()`, which requires a string subject. A malformed axial gap value such as `blockGap.top` being `array( '1rem' )` previously triggered an uncaught `TypeError`, breaking front-end rendering and REST API responses. Includes a direct unit test for `wp_sanitize_block_gap_value()` and a data provider case in `Tests_Block_Supports_Layout` covering rendering with a malformed axial block gap. Developed in #12604. Ports WordPress/gutenberg#80464 to Core. Props tyxla, ramonopoly. Fixes #65667. git-svn-id: https://develop.svn.wordpress.org/trunk@62801 602fd350-edb4-49c9-b593-d223f7449a82
Description
Fixes an uncaught
TypeErrorinwp_sanitize_block_gap_value()when ablockGapaxis holds a nested array rather than a scalar:The function iterates array gap values and passes each directly to
preg_match(), which requires a string subject. A malformed axial gap value such asblockGap.top=["1rem"]fatals, breaking front-end rendering and REST API responses.Non-scalar values are now treated as invalid and set to
null, and scalar values are cast to string for the regex check.This has been present since 6.0, when the array
foreachbranch was introduced in f187393.Testing Instructions
Automated
Manual
/wp-json/wp/v2/pages/<PAGE_ID>.Notes
Ports WordPress/gutenberg#80464 to core.
Trac ticket: https://core.trac.wordpress.org/ticket/65667
🤖 Generated with Claude Code