diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php
index c5093cc33b..4a0eea02f0 100644
a
|
b
|
function rest_validate_value_from_schema( $value, $args, $param = '' ) { |
1241 | 1241 | } |
1242 | 1242 | |
1243 | 1243 | if ( 'object' === $args['type'] ) { |
| 1244 | if ( '' === $value ) { |
| 1245 | $value = array(); |
| 1246 | } |
| 1247 | |
1244 | 1248 | if ( $value instanceof stdClass ) { |
1245 | 1249 | $value = (array) $value; |
1246 | 1250 | } |
diff --git a/tests/phpunit/tests/rest-api/rest-schema-sanitization.php b/tests/phpunit/tests/rest-api/rest-schema-sanitization.php
index 1b2fd1d90c..fc100f7b2b 100644
a
|
b
|
class WP_Test_REST_Schema_Sanitization extends WP_UnitTestCase { |
275 | 275 | $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( (object) array( 'a' => '1' ), $schema ) ); |
276 | 276 | } |
277 | 277 | |
| 278 | /** |
| 279 | * @ticket 42961 |
| 280 | */ |
| 281 | public function test_type_object_accepts_empty_string() { |
| 282 | $this->assertEquals( array(), rest_sanitize_value_from_schema( '', array( 'type' => 'object' ) ) ); |
| 283 | } |
| 284 | |
278 | 285 | public function test_type_unknown() { |
279 | 286 | $schema = array( |
280 | 287 | 'type' => 'lalala', |
diff --git a/tests/phpunit/tests/rest-api/rest-schema-validation.php b/tests/phpunit/tests/rest-api/rest-schema-validation.php
index 9c18a846dc..a6722d42a7 100644
a
|
b
|
class WP_Test_REST_Schema_Validation extends WP_UnitTestCase { |
288 | 288 | $this->assertTrue( rest_validate_value_from_schema( (object) array( 'a' => 1 ), $schema ) ); |
289 | 289 | } |
290 | 290 | |
| 291 | /** |
| 292 | * @ticket 42961 |
| 293 | */ |
| 294 | public function test_type_object_allows_empty_string() { |
| 295 | $this->assertTrue( rest_validate_value_from_schema( '', array( 'type' => 'object' ) ) ); |
| 296 | } |
| 297 | |
291 | 298 | public function test_type_unknown() { |
292 | 299 | $schema = array( |
293 | 300 | 'type' => 'lalala', |