diff --git a/src/wp-includes/rest-api/class-wp-rest-request.php b/src/wp-includes/rest-api/class-wp-rest-request.php index 9c5410a0ec..23156a31b0 100644 --- a/src/wp-includes/rest-api/class-wp-rest-request.php +++ b/src/wp-includes/rest-api/class-wp-rest-request.php @@ -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; diff --git a/tests/phpunit/tests/rest-api/rest-request.php b/tests/phpunit/tests/rest-api/rest-request.php index 925853c8cd..47d4c32c8f 100644 --- a/tests/phpunit/tests/rest-api/rest-request.php +++ b/tests/phpunit/tests/rest-api/rest-request.php @@ -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',