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
This commit is contained in:
Dion Hulse 2014-10-08 05:57:15 +00:00
parent e4268adfde
commit 4ae1397f96
2 changed files with 15 additions and 3 deletions

View File

@ -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'] : '/';

View File

@ -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/' ),
);
}
}