Changeset 47842
- Timestamp:
- 05/22/2020 08:46:03 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r47812 r47842 45 45 } 46 46 47 $clean_namespace = trim( $namespace, '/' ); 48 49 if ( $clean_namespace !== $namespace ) { 50 _doing_it_wrong( __FUNCTION__, __( 'Namespace must not start or end with a slash.' ), '5.4.2' ); 51 } 52 47 53 if ( ! did_action( 'rest_api_init' ) ) { 48 54 _doing_it_wrong( … … 85 91 } 86 92 87 $full_route = '/' . trim( $namespace, '/' ). '/' . trim( $route, '/' );88 rest_get_server()->register_route( $ namespace, $full_route, $args, $override );93 $full_route = '/' . $clean_namespace . '/' . trim( $route, '/' ); 94 rest_get_server()->register_route( $clean_namespace, $full_route, $args, $override ); 89 95 return true; 90 96 } -
trunk/tests/phpunit/tests/rest-api.php
r47758 r47842 984 984 public function test_rest_filter_response_by_context( $schema, $data, $expected ) { 985 985 $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() ); 986 1006 } 987 1007
Note: See TracChangeset
for help on using the changeset viewer.