mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-01 11:14:36 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@47842 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -985,6 +985,26 @@ class Tests_REST_API extends WP_UnitTestCase {
|
||||
$this->assertEquals( $expected, rest_filter_response_by_context( $data, $schema, 'view' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 49749
|
||||
*/
|
||||
public function test_register_route_with_invalid_namespace() {
|
||||
$this->setExpectedIncorrectUsage( 'register_rest_route' );
|
||||
|
||||
register_rest_route(
|
||||
'/my-namespace/v1/',
|
||||
'/my-route',
|
||||
array(
|
||||
'callback' => '__return_true',
|
||||
)
|
||||
);
|
||||
|
||||
$routes = rest_get_server()->get_routes( 'my-namespace/v1' );
|
||||
$this->assertCount( 2, $routes );
|
||||
|
||||
$this->assertTrue( rest_do_request( '/my-namespace/v1/my-route' )->get_data() );
|
||||
}
|
||||
|
||||
public function _dp_rest_filter_response_by_context() {
|
||||
return array(
|
||||
'default' => array(
|
||||
|
||||
Reference in New Issue
Block a user