Make WordPress Core

Ticket #42961: 42961.diff

File 42961.diff, 1.9 KB (added by TimothyBlynJacobs, 5 years ago)
  • src/wp-includes/rest-api.php

    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 = '' ) { 
    12411241        }
    12421242
    12431243        if ( 'object' === $args['type'] ) {
     1244                if ( '' === $value ) {
     1245                        $value = array();
     1246                }
     1247
    12441248                if ( $value instanceof stdClass ) {
    12451249                        $value = (array) $value;
    12461250                }
  • tests/phpunit/tests/rest-api/rest-schema-sanitization.php

    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 { 
    275275                $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( (object) array( 'a' => '1' ), $schema ) );
    276276        }
    277277
     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
    278285        public function test_type_unknown() {
    279286                $schema = array(
    280287                        'type' => 'lalala',
  • tests/phpunit/tests/rest-api/rest-schema-validation.php

    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 { 
    288288                $this->assertTrue( rest_validate_value_from_schema( (object) array( 'a' => 1 ), $schema ) );
    289289        }
    290290
     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
    291298        public function test_type_unknown() {
    292299                $schema = array(
    293300                        'type' => 'lalala',