Skip to content

Commit 4020b55

Browse files
Block Supports: Return early for non-array attributes in the shadow and spacing helpers.
1 parent aebff9e commit 4020b55

4 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎src/wp-includes/block-supports/shadow.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ function wp_apply_shadow_support( $block_type, $block_attributes ) {
7474
* @return array Array with `class` and `style` keys, each present only when non-empty.
7575
*/
7676
function wp_get_shadow_classes_and_styles( $block_attributes ) {
77+
if ( ! is_array( $block_attributes ) ) {
78+
return array();
79+
}
80+
7781
$shadow = $block_attributes['style']['shadow'] ?? null;
7882

7983
$attributes = array();

‎src/wp-includes/block-supports/spacing.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ function wp_apply_spacing_support( $block_type, $block_attributes ) {
8080
* @return array Array with `class` and `style` keys, each present only when non-empty.
8181
*/
8282
function wp_get_spacing_classes_and_styles( $block_attributes ) {
83+
if ( ! is_array( $block_attributes ) ) {
84+
return array();
85+
}
86+
8387
$spacing = $block_attributes['style']['spacing'] ?? null;
8488
if ( ! is_array( $spacing ) ) {
8589
return array();

‎tests/phpunit/tests/block-supports/wpGetShadowClassesAndStyles.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public function data_get_shadow_classes_and_styles() {
6262
'block_attributes' => null,
6363
'expected' => array(),
6464
),
65+
'object attributes' => array(
66+
'block_attributes' => (object) array( 'style' => array( 'shadow' => '1px 1px 1px #000' ) ),
67+
'expected' => array(),
68+
),
6569
);
6670
}
6771
}

‎tests/phpunit/tests/block-supports/wpGetSpacingClassesAndStyles.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ public function data_get_spacing_classes_and_styles() {
107107
),
108108
'expected' => array(),
109109
),
110+
'object attributes' => array(
111+
'block_attributes' => (object) array(
112+
'style' => array(
113+
'spacing' => array( 'margin' => '3px' ),
114+
),
115+
),
116+
'expected' => array(),
117+
),
110118
);
111119
}
112120
}

0 commit comments

Comments
 (0)