From 4ae1397f968d84419c5243dc8b2f314f35f687d6 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 8 Oct 2014 05:57:15 +0000 Subject: [PATCH] Correctly support Schemeless URLs in WP_HTTP::make_absolute_url() by respecting the 'host' field if present in the relative url. Fixes #29886 git-svn-id: https://develop.svn.wordpress.org/trunk@29851 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-http.php | 15 ++++++++++++--- tests/phpunit/tests/http/http.php | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/class-http.php b/src/wp-includes/class-http.php index b2b00623d8..c8330e09e2 100644 --- a/src/wp-includes/class-http.php +++ b/src/wp-includes/class-http.php @@ -686,9 +686,18 @@ class WP_Http { return $maybe_relative_path; } - $absolute_path = $url_parts['scheme'] . '://' . $url_parts['host']; - if ( isset( $url_parts['port'] ) ) - $absolute_path .= ':' . $url_parts['port']; + $absolute_path = $url_parts['scheme'] . '://'; + + // Schemeless URL's will make it this far, so we check for a host in the relative url and convert it to a protocol-url + if ( isset( $relative_url_parts['host'] ) ) { + $absolute_path .= $relative_url_parts['host']; + if ( isset( $relative_url_parts['port'] ) ) + $absolute_path .= ':' . $relative_url_parts['port']; + } else { + $absolute_path .= $url_parts['host']; + if ( isset( $url_parts['port'] ) ) + $absolute_path .= ':' . $url_parts['port']; + } // Start off with the Absolute URL path. $path = ! empty( $url_parts['path'] ) ? $url_parts['path'] : '/'; diff --git a/tests/phpunit/tests/http/http.php b/tests/phpunit/tests/http/http.php index 995220794f..b30eea54f6 100644 --- a/tests/phpunit/tests/http/http.php +++ b/tests/phpunit/tests/http/http.php @@ -61,6 +61,9 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { // 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/' ), + + // Schemeless URL's (Not valid in HTTP Headers, but may be used elsewhere) + array( '//example.com/sub/', 'https://example.net', 'https://example.com/sub/' ), ); } }