@ -18,7 +18,7 @@ var protocolPattern = /^([a-z0-9]+:)/,
path = require ( "path" ) , // internal module, guaranteed to be loaded already.
path = require ( "path" ) , // internal module, guaranteed to be loaded already.
querystring = require ( 'querystring' ) ;
querystring = require ( 'querystring' ) ;
function urlParse ( url , parseQueryString ) {
function urlParse ( url , parseQueryString , slashesDenoteHost ) {
if ( url && typeof ( url ) === "object" && url . href ) return url ;
if ( url && typeof ( url ) === "object" && url . href ) return url ;
var out = { href : url } ,
var out = { href : url } ,
@ -32,10 +32,15 @@ function urlParse (url, parseQueryString) {
}
}
// figure out if it's got a host
// figure out if it's got a host
var slashes = rest . substr ( 0 , 2 ) === "//" ;
// user@server is *always* interpreted as a hostname, and url
if ( slashes && ! ( proto && hostlessProtocol [ proto ] ) ) {
// resolution will treat //foo/bar as host=foo,path=bar because that's
rest = rest . substr ( 2 ) ;
// how the browser resolves relative URLs.
out . slashes = true ;
if ( slashesDenoteHost || proto || rest . match ( /^\/\/[^@\/]+@[^@\/]+/ ) ) {
var slashes = rest . substr ( 0 , 2 ) === "//" ;
if ( slashes && ! ( proto && hostlessProtocol [ proto ] ) ) {
rest = rest . substr ( 2 ) ;
out . slashes = true ;
}
}
}
if ( ! hostlessProtocol [ proto ] && ( slashes || ( proto && ! slashedProtocol [ proto ] ) ) ) {
if ( ! hostlessProtocol [ proto ] && ( slashes || ( proto && ! slashedProtocol [ proto ] ) ) ) {
// there's a hostname.
// there's a hostname.
@ -133,8 +138,8 @@ function urlResolve (source, relative) {
function urlResolveObject ( source , relative ) {
function urlResolveObject ( source , relative ) {
if ( ! source ) return relative ;
if ( ! source ) return relative ;
source = urlParse ( urlFormat ( source ) ) ;
source = urlParse ( urlFormat ( source ) , false , true ) ;
relative = urlParse ( urlFormat ( relative ) ) ;
relative = urlParse ( urlFormat ( relative ) , false , true ) ;
// hash is always overridden, no matter what.
// hash is always overridden, no matter what.
source . hash = relative . hash ;
source . hash = relative . hash ;