From e4268adfde062463780ca1f72bcdc6a730e09b64 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 8 Oct 2014 05:37:56 +0000 Subject: [PATCH] Correctly handle url's containing url's in WP_HTTP::make_absolute_url(). A valid relative URL could be mistaken for an absolute url if it contained a :// in any position of the url. Fixes #28001 git-svn-id: https://develop.svn.wordpress.org/trunk@29850 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-http.php | 9 +++++---- tests/phpunit/tests/http/http.php | 6 +++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/class-http.php b/src/wp-includes/class-http.php index 232ef69c3b..b2b00623d8 100644 --- a/src/wp-includes/class-http.php +++ b/src/wp-includes/class-http.php @@ -675,16 +675,17 @@ class WP_Http { if ( empty( $url ) ) return $maybe_relative_path; - // Check for a scheme. - if ( false !== strpos( $maybe_relative_path, '://' ) ) - return $maybe_relative_path; - if ( ! $url_parts = @parse_url( $url ) ) return $maybe_relative_path; if ( ! $relative_url_parts = @parse_url( $maybe_relative_path ) ) return $maybe_relative_path; + // Check for a scheme on the 'relative' url + if ( ! empty( $relative_url_parts['scheme'] ) ) { + return $maybe_relative_path; + } + $absolute_path = $url_parts['scheme'] . '://' . $url_parts['host']; if ( isset( $url_parts['port'] ) ) $absolute_path .= ':' . $url_parts['port']; diff --git a/tests/phpunit/tests/http/http.php b/tests/phpunit/tests/http/http.php index 578d6e84a8..995220794f 100644 --- a/tests/phpunit/tests/http/http.php +++ b/tests/phpunit/tests/http/http.php @@ -56,7 +56,11 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { array( 'otherfile.ext?query=string', 'http://example.com/file.ext?existing=query-string', 'http://example.com/otherfile.ext?query=string' ), // A file with a leading dot - array( '.ext', 'http://example.com/', 'http://example.com/.ext' ) + array( '.ext', 'http://example.com/', 'http://example.com/.ext' ), + + // URls within URLs + array( '/expected', 'http://example.com/sub/http://site.com/sub/', 'http://example.com/expected' ), + array( '/expected/http://site.com/sub/', 'http://example.com/', 'http://example.com/expected/http://site.com/sub/' ), ); } }