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. git-svn-id: https://develop.svn.wordpress.org/trunk@39087 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
5af14c3e07
commit
5d924daeb3
@ -451,7 +451,11 @@ class WP_REST_Request implements ArrayAccess {
|
||||
|
||||
$params = array();
|
||||
foreach ( $order as $type ) {
|
||||
$params = array_merge( $params, (array) $this->params[ $type ] );
|
||||
// array_merge / the "+" operator will mess up
|
||||
// numeric keys, so instead do a manual foreach.
|
||||
foreach ( (array) $this->params[ $type ] as $key => $value ) {
|
||||
$params[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $params;
|
||||
|
@ -286,6 +286,18 @@ class Tests_REST_Request extends WP_UnitTestCase {
|
||||
$this->assertEquals( $expected, $this->request->get_params() );
|
||||
}
|
||||
|
||||
public function test_parameter_merging_with_numeric_keys() {
|
||||
$this->request->set_query_params( array(
|
||||
'1' => 'hello',
|
||||
'2' => 'goodbye',
|
||||
) );
|
||||
$expected = array(
|
||||
'1' => 'hello',
|
||||
'2' => 'goodbye',
|
||||
);
|
||||
$this->assertEquals( $expected, $this->request->get_params() );
|
||||
}
|
||||
|
||||
public function test_sanitize_params() {
|
||||
$this->request->set_url_params( array(
|
||||
'someinteger' => '123',
|
||||
|
Loading…
Reference in New Issue
Block a user