Make WordPress Core

Changeset 47362


Ignore:
Timestamp:
02/25/2020 03:32:27 PM (6 years ago)
Author:
kadamwhite
Message:

REST API: Correctly infer empty objects passed via query parameters.

Permit passing an empty object as the string "?obj=". The type of the passed empty argument is inferred from the registered schema.

Props TimothyBlynJacobs, steffanhalv, schlessera, dd32.
Fixes #42961.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api.php

    r47224 r47362  
    12511251
    12521252        if ( 'object' === $args['type'] ) {
     1253                if ( '' === $value ) {
     1254                        $value = array();
     1255                }
     1256
    12531257                if ( $value instanceof stdClass ) {
    12541258                        $value = (array) $value;
  • trunk/tests/phpunit/tests/rest-api/rest-schema-sanitization.php

    r46586 r47362  
    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(
  • trunk/tests/phpunit/tests/rest-api/rest-schema-validation.php

    r46586 r47362  
    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(
Note: See TracChangeset for help on using the changeset viewer.