Changeset 59457
- Timestamp:
- 11/25/2024 10:08:05 AM (6 days ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r59456 r59457 2936 2936 } 2937 2937 2938 // Remove trailing slashes at the end of the REST API path (query part). 2938 2939 $path = untrailingslashit( $path ); 2939 2940 if ( empty( $path ) ) { … … 2944 2945 if ( false === $path_parts ) { 2945 2946 return $memo; 2947 } 2948 2949 if ( isset( $path_parts['path'] ) && '/' !== $path_parts['path'] ) { 2950 // Remove trailing slashes from the "path" part of the REST API path. 2951 $path_parts['path'] = untrailingslashit( $path_parts['path'] ); 2952 $path = str_contains( $path, '?' ) ? 2953 $path_parts['path'] . '?' . ( $path_parts['query'] ?? '' ) : 2954 $path_parts['path']; 2946 2955 } 2947 2956 -
trunk/tests/phpunit/tests/rest-api.php
r57133 r59457 961 961 962 962 /** 963 * @dataProvider data_rest_preload_api_request_removes_trailing_slashes 964 * 963 965 * @ticket 51636 964 */ 965 public function test_rest_preload_api_request_removes_trailing_slashes() { 966 * @ticket 57048 967 * 968 * @param string $preload_path The path to preload. 969 * @param array|string $expected_preload_path Expected path after preloading. 970 */ 971 public function test_rest_preload_api_request_removes_trailing_slashes( $preload_path, $expected_preload_path ) { 966 972 $rest_server = $GLOBALS['wp_rest_server']; 967 973 $GLOBALS['wp_rest_server'] = null; 968 974 969 $preload_paths = array( 970 '/wp/v2/types//', 971 array( '/wp/v2/media///', 'OPTIONS' ), 972 '////', 973 ); 974 975 $preload_data = array_reduce( 976 $preload_paths, 977 'rest_preload_api_request', 978 array() 979 ); 980 981 $this->assertSame( array_keys( $preload_data ), array( '/wp/v2/types', 'OPTIONS', '/' ) ); 982 $this->assertArrayHasKey( '/wp/v2/media', $preload_data['OPTIONS'] ); 975 $actual_preload_path = rest_preload_api_request( array(), $preload_path ); 976 if ( '' !== $preload_path ) { 977 $actual_preload_path = key( $actual_preload_path ); 978 } 979 $this->assertSame( $expected_preload_path, $actual_preload_path ); 983 980 984 981 $GLOBALS['wp_rest_server'] = $rest_server; 982 } 983 984 /** 985 * Data provider. 986 * 987 * @return array 988 */ 989 public static function data_rest_preload_api_request_removes_trailing_slashes() { 990 return array( 991 'no query part' => array( '/wp/v2/types//', '/wp/v2/types' ), 992 'no query part, more slashes' => array( '/wp/v2/media///', '/wp/v2/media' ), 993 'only slashes' => array( '////', '/' ), 994 'empty path' => array( '', array() ), 995 'no query parameters' => array( '/wp/v2/types//?////', '/wp/v2/types?' ), 996 'no query parameters, with slashes' => array( '/wp/v2/types//?fields////', '/wp/v2/types?fields' ), 997 'query parameters with no values' => array( '/wp/v2/types//?fields=////', '/wp/v2/types?fields=' ), 998 'single query parameter' => array( '/wp/v2/types//?_fields=foo,bar////', '/wp/v2/types?_fields=foo,bar' ), 999 'multiple query parameters' => array( '/wp/v2/types////?_fields=foo,bar&limit=1000////', '/wp/v2/types?_fields=foo,bar&limit=1000' ), 1000 ); 985 1001 } 986 1002
Note: See TracChangeset
for help on using the changeset viewer.