diff options
author | isaacs <i@izs.me> | 2010-08-31 17:59:50 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-09-02 09:24:21 -0700 |
commit | 0e311717b5bbec7f3fbf0b06592bfa19cc11becc (patch) | |
tree | 6574156779899dcc1f710e5b1289f3e63bee2224 /lib/url.js | |
parent | 7347fb3e2c445222598646262cec262f9dacee91 (diff) | |
download | android-node-v8-0e311717b5bbec7f3fbf0b06592bfa19cc11becc.tar.gz android-node-v8-0e311717b5bbec7f3fbf0b06592bfa19cc11becc.tar.bz2 android-node-v8-0e311717b5bbec7f3fbf0b06592bfa19cc11becc.zip |
Treat "//some_path" as pathname rather than hostname by default.
Note that "//" is still a special indicator for the hostname, and this does
not change the parsing of mailto: and other "slashless" url schemes. It
does however remove some oddness in url.parse(req.url) which is the most
common use-case for the url.parse function.
Diffstat (limited to 'lib/url.js')
-rw-r--r-- | lib/url.js | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/url.js b/lib/url.js index c4b534a5d5..45dea833b2 100644 --- a/lib/url.js +++ b/lib/url.js @@ -18,7 +18,7 @@ var protocolPattern = /^([a-z0-9]+:)/, path = require("path"), // internal module, guaranteed to be loaded already. querystring = require('querystring'); -function urlParse (url, parseQueryString) { +function urlParse (url, parseQueryString, slashesDenoteHost) { if (url && typeof(url) === "object" && url.href) return url; var out = { href : url }, @@ -32,10 +32,15 @@ function urlParse (url, parseQueryString) { } // figure out if it's got a host - var slashes = rest.substr(0, 2) === "//"; - if (slashes && !(proto && hostlessProtocol[proto])) { - rest = rest.substr(2); - out.slashes = true; + // user@server is *always* interpreted as a hostname, and url + // resolution will treat //foo/bar as host=foo,path=bar because that's + // how the browser resolves relative URLs. + 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]))) { // there's a hostname. @@ -133,8 +138,8 @@ function urlResolve (source, relative) { function urlResolveObject (source, relative) { if (!source) return relative; - source = urlParse(urlFormat(source)); - relative = urlParse(urlFormat(relative)); + source = urlParse(urlFormat(source), false, true); + relative = urlParse(urlFormat(relative), false, true); // hash is always overridden, no matter what. source.hash = relative.hash; |