Make WordPress Core

Changeset 35659


Ignore:
Timestamp:
11/18/2015 07:23:38 AM (10 years ago)
Author:
rmccue
Message:

REST API: Remove redundant "0" parameter.

This is just an artifact of how we parse the URL, and is already available
via $request->get_route()

Props danielbachhuber.
Fixes #34647.

Location:
trunk
Files:
2 edited

Legend:

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

    r35653 r35659  
    790790
    791791                if ( ! is_wp_error( $response ) ) {
     792                    // Remove the redundant preg_match argument.
     793                    unset( $args[0] );
    792794
    793795                    $request->set_url_params( $args );
  • trunk/tests/phpunit/tests/rest-api/rest-server.php

    r35654 r35659  
    105105        $this->assertEquals( 200, $response->get_status() );
    106106        $this->assertArrayNotHasKey( 'foo', (array) $request );
     107    }
     108
     109    public function test_no_zero_param() {
     110        register_rest_route( 'no-zero', '/test', array(
     111            'methods'  => array( 'GET' ),
     112            'callback' => '__return_null',
     113            'args'     => array(
     114                'foo'  => array(
     115                    'default'    => 'bar',
     116                ),
     117            ),
     118        ) );
     119        $request = new WP_REST_Request( 'GET', '/no-zero/test' );
     120        $this->server->dispatch( $request );
     121        $this->assertEquals( array( 'foo' => 'bar' ), $request->get_params() );
    107122    }
    108123
Note: See TracChangeset for help on using the changeset viewer.