Make WordPress Core


Ignore:
Timestamp:
08/03/2017 07:54:56 PM (8 years ago)
Author:
jnylen0
Message:

REST API: Exclude numeric parameters from regex parsing

The list of endpoint parameters should only include explicitly named and requested parameters.

Props flixos90, rmccue, jnylen0.
Fixes #40704.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-server.php

    r40805 r41223  
    161161        $response = $this->server->dispatch( $request );
    162162        $this->assertEquals( 200, $response->get_status() );
     163    }
     164
     165    public function test_url_params_no_numeric_keys() {
     166
     167        $this->server->register_route( 'test', '/test/(?P<data>.*)', array(
     168            array(
     169                'methods'  => WP_REST_Server::READABLE,
     170                'callback' => '__return_false',
     171                'args'     => array(
     172                    'data' => array(),
     173                ),
     174            ),
     175        ) );
     176
     177        $request = new WP_REST_Request( 'GET', '/test/some-value' );
     178        $this->server->dispatch( $request );
     179        $this->assertEquals( array( 'data' => 'some-value' ), $request->get_params() );
    163180    }
    164181
Note: See TracChangeset for help on using the changeset viewer.