Make WordPress Core


Ignore:
Timestamp:
02/24/2020 06:05:12 PM (6 years ago)
Author:
kadamwhite
Message:

REST API: Fix namespace shadowing issue in route matching logic.

Following [47260] a namespace such as "test-ns" prevents any namespace such as "test-ns/v1" from being found when matching routes.
While not best practice, this was an unintentional back-compat break; this patch restores the original behavior.

Props david.binda, TimothyBlynJacobs.
Fixes #48530.

File:
1 edited

Legend:

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

    r47326 r47351  
    14661466        }
    14671467
     1468        /**
     1469         * @ticket 48530
     1470         */
     1471        public function test_get_routes_no_namespace_overriding() {
     1472                register_rest_route(
     1473                        'test-ns',
     1474                        '/test',
     1475                        array(
     1476                                'methods'  => array( 'GET' ),
     1477                                'callback' => function() {
     1478                                        return new WP_REST_Response( 'data', 204 );
     1479                                },
     1480                        )
     1481                );
     1482                register_rest_route(
     1483                        'test-ns/v1',
     1484                        '/test',
     1485                        array(
     1486                                'methods'  => array( 'GET' ),
     1487                                'callback' => function() {
     1488                                        return new WP_REST_Response( 'data', 204 );
     1489                                },
     1490                        )
     1491                );
     1492
     1493                $request  = new WP_REST_Request( 'GET', '/test-ns/v1/test' );
     1494                $response = rest_get_server()->dispatch( $request );
     1495
     1496                $this->assertEquals( 204, $response->get_status(), '/test-ns/v1/test' );
     1497        }
     1498
    14681499        public function _validate_as_integer_123( $value, $request, $key ) {
    14691500                if ( ! is_int( $value ) ) {
Note: See TracChangeset for help on using the changeset viewer.