diff --git src/wp-includes/rest-api.php src/wp-includes/rest-api.php
index 82d856a063..cba8182af4 100644
|
|
function get_rest_url( $blog_id = null, $path = '/', $scheme = 'rest' ) { |
307 | 307 | $path = '/'; |
308 | 308 | } |
309 | 309 | |
| 310 | $path = '/' . ltrim( $path, '/' ); |
| 311 | |
310 | 312 | if ( is_multisite() && get_blog_option( $blog_id, 'permalink_structure' ) || get_option( 'permalink_structure' ) ) { |
311 | 313 | global $wp_rewrite; |
312 | 314 | |
… |
… |
function get_rest_url( $blog_id = null, $path = '/', $scheme = 'rest' ) { |
316 | 318 | $url = get_home_url( $blog_id, rest_get_url_prefix(), $scheme ); |
317 | 319 | } |
318 | 320 | |
319 | | $url .= '/' . ltrim( $path, '/' ); |
| 321 | $url .= $path; |
320 | 322 | } else { |
321 | 323 | $url = trailingslashit( get_home_url( $blog_id, '', $scheme ) ); |
322 | 324 | // nginx only allows HTTP/1.0 methods when redirecting from / to /index.php |
… |
… |
function get_rest_url( $blog_id = null, $path = '/', $scheme = 'rest' ) { |
325 | 327 | $url .= 'index.php'; |
326 | 328 | } |
327 | 329 | |
328 | | $path = '/' . ltrim( $path, '/' ); |
329 | | |
330 | 330 | $url = add_query_arg( 'rest_route', $path, $url ); |
331 | 331 | } |
332 | 332 | |
diff --git tests/phpunit/tests/rest-api.php tests/phpunit/tests/rest-api.php
index 45c1ccef71..68a07c8899 100644
|
|
class Tests_REST_API extends WP_UnitTestCase { |
488 | 488 | |
489 | 489 | } |
490 | 490 | |
| 491 | /** |
| 492 | * @ticket 42452 |
| 493 | */ |
| 494 | public function test_always_prepend_path_with_slash_in_rest_url_filter() { |
| 495 | $filter = new MockAction(); |
| 496 | add_filter( 'rest_url', array( $filter, 'filter' ), 10, 2 ); |
| 497 | |
| 498 | // Passing no path should return a slash. |
| 499 | get_rest_url(); |
| 500 | $args = $filter->get_args(); |
| 501 | $this->assertEquals( '/', $args[0][1] ); |
| 502 | $filter->reset(); |
| 503 | |
| 504 | // Paths without a prepended slash should have one added. |
| 505 | get_rest_url( null, 'wp/media/' ); |
| 506 | $args = $filter->get_args(); |
| 507 | $this->assertEquals( '/wp/media/', $args[0][1] ); |
| 508 | $filter->reset(); |
| 509 | |
| 510 | // Do not modify paths with a prepended slash. |
| 511 | get_rest_url( null, '/wp/media/' ); |
| 512 | $args = $filter->get_args(); |
| 513 | $this->assertEquals( '/wp/media/', $args[0][1] ); |
| 514 | |
| 515 | unset( $filter ); |
| 516 | } |
| 517 | |
491 | 518 | public function jsonp_callback_provider() { |
492 | 519 | return array( |
493 | 520 | // Standard names |