WordPress.org

Make WordPress Core

Changeset 29851


Ignore:
Timestamp:
10/08/2014 05:57:15 AM (5 years ago)
Author:
dd32
Message:

Correctly support Schemeless URLs in WP_HTTP::make_absolute_url() by respecting the 'host' field if present in the relative url.
Fixes #29886

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-http.php

    r29850 r29851  
    687687        }
    688688
    689         $absolute_path = $url_parts['scheme'] . '://' . $url_parts['host'];
    690         if ( isset( $url_parts['port'] ) )
    691             $absolute_path .= ':' . $url_parts['port'];
     689        $absolute_path = $url_parts['scheme'] . '://';
     690
     691        // 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
     692        if ( isset( $relative_url_parts['host'] ) ) {
     693            $absolute_path .= $relative_url_parts['host'];
     694            if ( isset( $relative_url_parts['port'] ) )
     695                $absolute_path .= ':' . $relative_url_parts['port'];
     696        } else {
     697            $absolute_path .= $url_parts['host'];
     698            if ( isset( $url_parts['port'] ) )
     699                $absolute_path .= ':' . $url_parts['port'];
     700        }
    692701
    693702        // Start off with the Absolute URL path.
  • trunk/tests/phpunit/tests/http/http.php

    r29850 r29851  
    6262            array( '/expected', 'http://example.com/sub/http://site.com/sub/', 'http://example.com/expected' ),
    6363            array( '/expected/http://site.com/sub/', 'http://example.com/', 'http://example.com/expected/http://site.com/sub/' ),
     64
     65            // Schemeless URL's (Not valid in HTTP Headers, but may be used elsewhere)
     66            array( '//example.com/sub/', 'https://example.net', 'https://example.com/sub/' ),
    6467        );
    6568    }
Note: See TracChangeset for help on using the changeset viewer.