From 1ead20f27466438600be03af9cc92073e8f44c13 Mon Sep 17 00:00:00 2001 From: seebees Date: Fri, 14 Oct 2011 17:13:16 -0700 Subject: [PATCH] remove auth from host Fixes #1626 --- lib/url.js | 23 +++++++++-------------- test/simple/test-url.js | 18 +++++++++--------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/lib/url.js b/lib/url.js index e6915b42c59..f6d86316519 100644 --- a/lib/url.js +++ b/lib/url.js @@ -169,7 +169,6 @@ function urlParse(url, parseQueryString, slashesDenoteHost) { // pull out port. var p = parseHost(out.host); - if (out.auth) out.host = out.auth + '@' + out.host; var keys = Object.keys(p); for (var i = 0, l = keys.length; i < l; i++) { var key = keys[i]; @@ -235,8 +234,7 @@ function urlParse(url, parseQueryString, slashesDenoteHost) { } out.hostname = newOut.join('.'); - out.host = ((out.auth) ? out.auth + '@' : '') + - (out.hostname || '') + + out.host = (out.hostname || '') + ((out.port) ? ':' + out.port : ''); out.href += out.host; } @@ -314,20 +312,20 @@ function urlFormat(obj) { // to clean up potentially wonky urls. if (typeof(obj) === 'string') obj = urlParse(obj); - var auth = obj.auth; + var auth = obj.auth || ''; if (auth) { auth = auth.split('@').join('%40'); for (var i = 0, l = nonAuthChars.length; i < l; i++) { var nAC = nonAuthChars[i]; auth = auth.split(nAC).join(encodeURIComponent(nAC)); } + auth += '@'; } var protocol = obj.protocol || '', - host = (obj.host !== undefined) ? obj.host : + host = (obj.host !== undefined) ? auth + obj.host : obj.hostname !== undefined ? ( - (auth ? auth + '@' : '') + - obj.hostname + + auth + obj.hostname + (obj.port ? ':' + obj.port : '') ) : false, @@ -449,17 +447,14 @@ function urlResolveObject(source, relative) { if (psychotic) { delete source.hostname; - delete source.auth; delete source.port; if (source.host) { if (srcPath[0] === '') srcPath[0] = source.host; else srcPath.unshift(source.host); } delete source.host; - if (relative.protocol) { delete relative.hostname; - delete relative.auth; delete relative.port; if (relative.host) { if (relPath[0] === '') relPath[0] = relative.host; @@ -501,7 +496,7 @@ function urlResolveObject(source, relative) { source.host.split('@') : false; if (authInHost) { source.auth = authInHost.shift(); - source.hostname = authInHost.shift(); + source.host = source.hostname = authInHost.shift(); } } source.search = relative.search; @@ -580,8 +575,8 @@ function urlResolveObject(source, relative) { var authInHost = source.host && source.host.indexOf('@') > 0 ? source.host.split('@') : false; if (authInHost) { - relative.auth = authInHost.shift(); - source.hostname = authInHost.shift(); + source.auth = authInHost.shift(); + source.host = source.hostname = authInHost.shift(); } } @@ -597,7 +592,7 @@ function urlResolveObject(source, relative) { source.path = (source.pathname ? source.pathname : '') + (source.search ? source.search : ''); } - source.auth = relative.auth; + source.auth = relative.auth || source.auth; source.slashes = source.slashes || relative.slashes; source.href = urlFormat(source); return source; diff --git a/test/simple/test-url.js b/test/simple/test-url.js index a70127e1022..ca6782ed9b5 100644 --- a/test/simple/test-url.js +++ b/test/simple/test-url.js @@ -56,7 +56,7 @@ var parseTests = { 'protocol': 'http:', 'slashes': true, 'auth': 'user:pw', - 'host': 'user:pw@www.example.com', + 'host': 'www.example.com', 'hostname': 'www.example.com', 'pathname': '/', 'path': '/' @@ -66,7 +66,7 @@ var parseTests = { 'protocol': 'http:', 'slashes': true, 'auth': 'USER:PW', - 'host': 'USER:PW@www.example.com', + 'host': 'www.example.com', 'hostname': 'www.example.com', 'pathname': '/', 'path': '/' @@ -184,7 +184,7 @@ var parseTests = { '&hl=en&src=api&x=2&y=2&z=3&s=', 'protocol': 'http:', 'slashes': true, - 'host': 'user:pass@mt0.google.com', + 'host': 'mt0.google.com', 'auth': 'user:pass', 'hostname': 'mt0.google.com', 'search': '???&hl=en&src=api&x=2&y=2&z=3&s=', @@ -256,7 +256,7 @@ var parseTests = { 'href': 'http://user:pass@example.com:8000/foo/bar?baz=quux#frag', 'protocol': 'http:', 'slashes': true, - 'host': 'user:pass@example.com:8000', + 'host': 'example.com:8000', 'auth': 'user:pass', 'port': '8000', 'hostname': 'example.com', @@ -269,7 +269,7 @@ var parseTests = { '//user:pass@example.com:8000/foo/bar?baz=quux#frag' : { 'href': '//user:pass@example.com:8000/foo/bar?baz=quux#frag', 'slashes': true, - 'host': 'user:pass@example.com:8000', + 'host': 'example.com:8000', 'auth': 'user:pass', 'port': '8000', 'hostname': 'example.com', @@ -299,7 +299,7 @@ var parseTests = { 'mailto:foo@bar.com?subject=hello' : { 'href': 'mailto:foo@bar.com?subject=hello', 'protocol': 'mailto:', - 'host': 'foo@bar.com', + 'host': 'bar.com', 'auth' : 'foo', 'hostname' : 'bar.com', 'search': '?subject=hello', @@ -315,7 +315,7 @@ var parseTests = { 'xmpp:isaacschlueter@jabber.org' : { 'href': 'xmpp:isaacschlueter@jabber.org', 'protocol': 'xmpp:', - 'host': 'isaacschlueter@jabber.org', + 'host': 'jabber.org', 'auth': 'isaacschlueter', 'hostname': 'jabber.org' }, @@ -323,7 +323,7 @@ var parseTests = { 'href' : 'http://atpass:foo%40bar@127.0.0.1:8080/path?search=foo#bar', 'protocol' : 'http:', 'slashes': true, - 'host' : 'atpass:foo%40bar@127.0.0.1:8080', + 'host' : '127.0.0.1:8080', 'auth' : 'atpass:foo%40bar', 'hostname' : '127.0.0.1', 'port' : '8080', @@ -557,7 +557,7 @@ var formatTests = { 'xmpp:isaacschlueter@jabber.org' : { 'href': 'xmpp:isaacschlueter@jabber.org', 'protocol': 'xmpp:', - 'host': 'isaacschlueter@jabber.org', + 'host': 'jabber.org', 'auth': 'isaacschlueter', 'hostname': 'jabber.org' },