From dd2bcd86b4acf7bcfeece652a8cdfac79ba35be4 Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Mon, 20 Jul 2026 10:45:12 +0300 Subject: [PATCH 1/2] Block Supports: Handle nested array block gap values properly --- lib/block-supports/layout.php | 2 +- phpunit/block-supports/layout-test.php | 44 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index 44e95a44be7248..7a93a510dbbddd 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -290,7 +290,7 @@ function gutenberg_get_layout_container_values( $layout ) { function gutenberg_sanitize_block_gap_value( $gap_value ) { if ( is_array( $gap_value ) ) { foreach ( $gap_value as $key => $value ) { - $gap_value[ $key ] = $value && preg_match( '%[\\\(&=}]|/\*%', $value ) ? null : $value; + $gap_value[ $key ] = ! is_scalar( $value ) || ( $value && preg_match( '%[\\\(&=}]|/\*%', (string) $value ) ) ? null : $value; } return $gap_value; } diff --git a/phpunit/block-supports/layout-test.php b/phpunit/block-supports/layout-test.php index bf38867e91ee10..1a27f947622ccd 100644 --- a/phpunit/block-supports/layout-test.php +++ b/phpunit/block-supports/layout-test.php @@ -72,6 +72,24 @@ public function filter_set_theme_root() { return $this->theme_root; } + /** + * @covers ::gutenberg_sanitize_block_gap_value + */ + public function test_sanitize_block_gap_value_rejects_nested_array_values() { + $this->assertSame( + array( + 'top' => null, + 'left' => '2rem', + ), + gutenberg_sanitize_block_gap_value( + array( + 'top' => array( '1rem' ), + 'left' => '2rem', + ) + ) + ); + } + public function test_outer_container_not_restored_for_non_aligned_image_block_with_non_themejson_theme() { // The "default" theme doesn't have theme.json support. switch_theme( 'default' ); @@ -636,6 +654,32 @@ public function data_layout_support_flag_renders_classnames_on_wrapper() { ), 'expected_output' => '
', ), + 'single wrapper block layout with malformed axial block gap' => array( + 'args' => array( + 'block_content' => '
', + 'block' => array( + 'blockName' => 'core/group', + 'attrs' => array( + 'layout' => array( + 'type' => 'default', + ), + 'style' => array( + 'spacing' => array( + 'blockGap' => array( + 'top' => array( '1rem' ), + ), + ), + ), + ), + 'innerBlocks' => array(), + 'innerHTML' => '
', + 'innerContent' => array( + '
', + ), + ), + ), + 'expected_output' => '
', + ), 'single wrapper block layout with constrained type' => array( 'args' => array( 'block_content' => '
', From 673ebeb0638dfc2d85daafe8e22b98a6fde8a654 Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Mon, 20 Jul 2026 11:13:36 +0300 Subject: [PATCH 2/2] Backport Changelog: Add entry for Core PR 12604 --- backport-changelog/7.1/12604.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 backport-changelog/7.1/12604.md diff --git a/backport-changelog/7.1/12604.md b/backport-changelog/7.1/12604.md new file mode 100644 index 00000000000000..62faed63df4653 --- /dev/null +++ b/backport-changelog/7.1/12604.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/12604 + +* https://github.com/WordPress/gutenberg/pull/80464