Skip to content

Commit 0aa5ecc

Browse files
Merge branch 'trunk' into fix/64226-variable-naming-compliance
2 parents 5d79ae3 + b7cb91c commit 0aa5ecc

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/wp-includes/style-engine/class-wp-style-engine-css-declarations.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public function add_declaration( $property, $value ) {
5959
return $this;
6060
}
6161

62+
// Bail early if value is not a string. Prevents fatal errors from malformed block markup.
63+
if ( ! is_string( $value ) ) {
64+
return $this;
65+
}
66+
6267
// Trims the value. If empty, bail early.
6368
$value = trim( $value );
6469
if ( '' === $value ) {

tests/phpunit/tests/style-engine/wpStyleEngineCssDeclarations.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,32 @@ public function test_should_remove_multiple_declarations() {
290290
'Output after removing "color" and "margin" declarations via `remove_declarations()` does not match expectations'
291291
);
292292
}
293+
294+
/**
295+
* Tests that non-string values are rejected without causing fatal errors.
296+
*
297+
* @ticket 64545
298+
*
299+
* @covers ::add_declaration
300+
*/
301+
public function test_should_reject_non_string_values() {
302+
$css_declarations = new WP_Style_Engine_CSS_Declarations();
303+
304+
// Add valid string value first.
305+
$css_declarations->add_declaration( 'color', 'red' );
306+
307+
// Try to add array value - should be silently rejected.
308+
$css_declarations->add_declaration( 'padding-margin', array( 'top' => '10px' ) );
309+
310+
// Try to add other non-string values.
311+
$css_declarations->add_declaration( 'font-size', 123 );
312+
$css_declarations->add_declaration( 'margin', null );
313+
314+
// Only the valid string value should be stored.
315+
$this->assertSame(
316+
array( 'color' => 'red' ),
317+
$css_declarations->get_declarations(),
318+
'Non-string values should be rejected without causing errors.'
319+
);
320+
}
293321
}

0 commit comments

Comments
 (0)