Skip to content

Editor: Handle nested array block gap values properly - #12604

Closed
tyxla wants to merge 1 commit into
WordPress:trunkfrom
tyxla:backport/gutenberg-80464-block-gap-nested-array
Closed

Editor: Handle nested array block gap values properly#12604
tyxla wants to merge 1 commit into
WordPress:trunkfrom
tyxla:backport/gutenberg-80464-block-gap-nested-array

Conversation

@tyxla

@tyxla tyxla commented Jul 20, 2026

Copy link
Copy Markdown
Member

Description

Fixes an uncaught TypeError in wp_sanitize_block_gap_value() when a blockGap axis holds a nested array rather than a scalar:

Fatal error: Uncaught TypeError: preg_match(): Argument #2 ($subject) must be of type string, array given in wp-includes/block-supports/layout.php:89

The function iterates array gap values and passes each directly to preg_match(), which requires a string subject. A malformed axial gap value such as blockGap.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 foreach branch was introduced in f187393.

Testing Instructions

Automated

npm run test:php -- --filter Tests_Block_Supports_Layout

Manual

  1. Create and publish a page.
  2. Open the code editor and replace the content with:
<!-- wp:group {"style":{"spacing":{"blockGap":{"top":["1rem"],"left":"2rem"}}},"layout":{"type":"default"}} -->
<div class="wp-block-group">
	<!-- wp:paragraph -->
	<p>Malformed block gap reproduction</p>
	<!-- /wp:paragraph -->
</div>
<!-- /wp:group -->
  1. Update and view the page.
  2. Open /wp-json/wp/v2/pages/<PAGE_ID>.
  3. Confirm the page and REST response load without the fatal error.

Notes

Ports WordPress/gutenberg#80464 to core.

Trac ticket: https://core.trac.wordpress.org/ticket/65667

🤖 Generated with Claude Code

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.
@github-actions

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.

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

@tyxla tyxla self-assigned this Jul 20, 2026
@tyxla
tyxla requested a review from tellthemachines July 20, 2026 08:11
@tyxla tyxla assigned talldan and unassigned talldan Jul 20, 2026
@tyxla
tyxla requested a review from talldan July 20, 2026 08:11
@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.

pento pushed a commit that referenced this pull request Jul 20, 2026
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
@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: 62801
GitHub commit: 7a7652e

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 20, 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.

2 participants

Sponsor
SponsoredKunjungi sekarang
Promo