WordPress.org

Make WordPress Core

Changeset 39087


Ignore:
Timestamp:
11/02/16 05:52:12 (12 months ago)
Author:
rmccue
Message:

REST API: Change method of merging parameters.

array_merge() incorrectly reindexes numeric parameters, causing things like {"123": true} to be "dropped".

Props sswells, joehoyle.
Fixes #38306.

Location:
trunk
Files:
2 edited

Legend:

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

    r39027 r39087  
    452452        $params = array(); 
    453453        foreach ( $order as $type ) { 
    454             $params = array_merge( $params, (array) $this->params[ $type ] ); 
     454            // array_merge / the "+" operator will mess up 
     455            // numeric keys, so instead do a manual foreach. 
     456            foreach ( (array) $this->params[ $type ] as $key => $value ) { 
     457                $params[ $key ] = $value; 
     458            } 
    455459        } 
    456460 
  • trunk/tests/phpunit/tests/rest-api/rest-request.php

    r38601 r39087  
    283283            'has_body_params'    => true, 
    284284            'has_default_params' => true, 
     285        ); 
     286        $this->assertEquals( $expected, $this->request->get_params() ); 
     287    } 
     288 
     289    public function test_parameter_merging_with_numeric_keys() { 
     290        $this->request->set_query_params( array( 
     291            '1'           => 'hello', 
     292            '2'           => 'goodbye', 
     293        ) ); 
     294        $expected = array( 
     295            '1'           => 'hello', 
     296            '2'           => 'goodbye', 
    285297        ); 
    286298        $this->assertEquals( $expected, $this->request->get_params() ); 
Note: See TracChangeset for help on using the changeset viewer.