mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
REST API: Remove trailing slashes when preloading requests and add unit tests for it.
Props antonvlasenko. Fixes #51636. git-svn-id: https://develop.svn.wordpress.org/trunk@51648 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
40506e7e64
commit
fe3d953437
@ -2818,6 +2818,11 @@ function rest_preload_api_request( $memo, $path ) {
|
||||
}
|
||||
}
|
||||
|
||||
$path = untrailingslashit( $path );
|
||||
if ( empty( $path ) ) {
|
||||
$path = '/';
|
||||
}
|
||||
|
||||
$path_parts = parse_url( $path );
|
||||
if ( false === $path_parts ) {
|
||||
return $memo;
|
||||
|
||||
@ -954,6 +954,31 @@ class Tests_REST_API extends WP_UnitTestCase {
|
||||
$GLOBALS['wp_rest_server'] = $rest_server;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 51636
|
||||
*/
|
||||
function test_rest_preload_api_request_removes_trailing_slashes() {
|
||||
$rest_server = $GLOBALS['wp_rest_server'];
|
||||
$GLOBALS['wp_rest_server'] = null;
|
||||
|
||||
$preload_paths = array(
|
||||
'/wp/v2/types//',
|
||||
array( '/wp/v2/media///', 'OPTIONS' ),
|
||||
'////',
|
||||
);
|
||||
|
||||
$preload_data = array_reduce(
|
||||
$preload_paths,
|
||||
'rest_preload_api_request',
|
||||
array()
|
||||
);
|
||||
|
||||
$this->assertSame( array_keys( $preload_data ), array( '/wp/v2/types', 'OPTIONS', '/' ) );
|
||||
$this->assertArrayHasKey( '/wp/v2/media', $preload_data['OPTIONS'] );
|
||||
|
||||
$GLOBALS['wp_rest_server'] = $rest_server;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40614
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user