diff --git a/src/wp-includes/class-http.php b/src/wp-includes/class-http.php index 9d5fca0eab..2fd4c54ea6 100644 --- a/src/wp-includes/class-http.php +++ b/src/wp-includes/class-http.php @@ -362,6 +362,9 @@ class WP_Http { } } + // Work around a bug in Requests when the path starts with // See https://github.com/rmccue/Requests/issues/231 + $url = preg_replace( '!^(\w+://[^/]+)//(.*)$!i', '$1/$2', $url ); + try { $requests_response = Requests::request( $url, $headers, $data, $type, $options ); diff --git a/tests/phpunit/tests/http/base.php b/tests/phpunit/tests/http/base.php index 671e2ae08c..e1e5b0747c 100644 --- a/tests/phpunit/tests/http/base.php +++ b/tests/phpunit/tests/http/base.php @@ -376,5 +376,18 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { $this->assertTrue( ! is_wp_error( $res ), print_r( $res, true ) ); } + /** + * @ticket 37733 + */ + function test_url_with_double_slashes_path() { + $url = $this->redirection_script . '?rt=' . 0; + + $path = parse_url( $url, PHP_URL_PATH ); + $url = str_replace( $path, '/' . $path, $url ); + + $res = wp_remote_request( $url ); + $this->assertNotWPError( $res ); + } + }