Make WordPress Core


Ignore:
Timestamp:
05/22/2020 08:46:03 PM (5 years ago)
Author:
whyisjake
Message:

REST API: Ensure proper namespacing when registering routes.

The PR will corerce routes that have a leading slash and throwing a _doing_it_wrong notice while ensuring a proper namespace.

Fixes #49749.
Props TimothyBlynJacobs, skarabeq, afercia.

File:
1 edited

Legend:

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

    r47758 r47842  
    984984    public function test_rest_filter_response_by_context( $schema, $data, $expected ) {
    985985        $this->assertEquals( $expected, rest_filter_response_by_context( $data, $schema, 'view' ) );
     986    }
     987
     988    /**
     989     * @ticket 49749
     990     */
     991    public function test_register_route_with_invalid_namespace() {
     992        $this->setExpectedIncorrectUsage( 'register_rest_route' );
     993
     994        register_rest_route(
     995            '/my-namespace/v1/',
     996            '/my-route',
     997            array(
     998                'callback' => '__return_true',
     999            )
     1000        );
     1001
     1002        $routes = rest_get_server()->get_routes( 'my-namespace/v1' );
     1003        $this->assertCount( 2, $routes );
     1004
     1005        $this->assertTrue( rest_do_request( '/my-namespace/v1/my-route' )->get_data() );
    9861006    }
    9871007
Note: See TracChangeset for help on using the changeset viewer.