0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

remove auth from host

Fixes #1626
This commit is contained in:
seebees 2011-10-14 17:13:16 -07:00 committed by koichik
parent 005d607aed
commit 1ead20f274
2 changed files with 18 additions and 23 deletions

View File

@ -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;

View File

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