Ignore an empty port component when parsing URLs.
This commit is contained in:
parent
a10cfba766
commit
677c2c112c
@ -31,7 +31,7 @@ exports.format = urlFormat;
|
|||||||
// define these here so at least they only have to be
|
// define these here so at least they only have to be
|
||||||
// compiled once on the first module load.
|
// compiled once on the first module load.
|
||||||
var protocolPattern = /^([a-z0-9.+-]+:)/i,
|
var protocolPattern = /^([a-z0-9.+-]+:)/i,
|
||||||
portPattern = /:[0-9]+$/,
|
portPattern = /:[0-9]*$/,
|
||||||
// RFC 2396: characters reserved for delimiting URLs.
|
// RFC 2396: characters reserved for delimiting URLs.
|
||||||
delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
|
delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
|
||||||
// RFC 2396: characters not allowed for various reasons.
|
// RFC 2396: characters not allowed for various reasons.
|
||||||
@ -625,7 +625,9 @@ function parseHost(host) {
|
|||||||
var port = portPattern.exec(host);
|
var port = portPattern.exec(host);
|
||||||
if (port) {
|
if (port) {
|
||||||
port = port[0];
|
port = port[0];
|
||||||
out.port = port.substr(1);
|
if (port !== ':') {
|
||||||
|
out.port = port.substr(1);
|
||||||
|
}
|
||||||
host = host.substr(0, host.length - port.length);
|
host = host.substr(0, host.length - port.length);
|
||||||
}
|
}
|
||||||
if (host) out.hostname = host;
|
if (host) out.hostname = host;
|
||||||
|
@ -545,6 +545,58 @@ var parseTests = {
|
|||||||
'query': 'n=Temperature',
|
'query': 'n=Temperature',
|
||||||
'pathname': '/.well-known/r',
|
'pathname': '/.well-known/r',
|
||||||
'path': '/.well-known/r?n=Temperature'
|
'path': '/.well-known/r?n=Temperature'
|
||||||
|
},
|
||||||
|
// empty port
|
||||||
|
'http://example.com:': {
|
||||||
|
'protocol': 'http:',
|
||||||
|
'slashes': true,
|
||||||
|
'host': 'example.com',
|
||||||
|
'hostname': 'example.com',
|
||||||
|
'href': 'http://example.com/',
|
||||||
|
'pathname': '/',
|
||||||
|
'path': '/'
|
||||||
|
},
|
||||||
|
'http://example.com:/a/b.html': {
|
||||||
|
'protocol': 'http:',
|
||||||
|
'slashes': true,
|
||||||
|
'host': 'example.com',
|
||||||
|
'hostname': 'example.com',
|
||||||
|
'href': 'http://example.com/a/b.html',
|
||||||
|
'pathname': '/a/b.html',
|
||||||
|
'path': '/a/b.html'
|
||||||
|
},
|
||||||
|
'http://example.com:?a=b': {
|
||||||
|
'protocol': 'http:',
|
||||||
|
'slashes': true,
|
||||||
|
'host': 'example.com',
|
||||||
|
'hostname': 'example.com',
|
||||||
|
'href': 'http://example.com/?a=b',
|
||||||
|
'search': '?a=b',
|
||||||
|
'query': 'a=b',
|
||||||
|
'pathname': '/',
|
||||||
|
'path': '/?a=b'
|
||||||
|
},
|
||||||
|
'http://example.com:#abc': {
|
||||||
|
'protocol': 'http:',
|
||||||
|
'slashes': true,
|
||||||
|
'host': 'example.com',
|
||||||
|
'hostname': 'example.com',
|
||||||
|
'href': 'http://example.com/#abc',
|
||||||
|
'hash': '#abc',
|
||||||
|
'pathname': '/',
|
||||||
|
'path': '/'
|
||||||
|
},
|
||||||
|
'http://[fe80::1]:/a/b?a=b#abc': {
|
||||||
|
'protocol': 'http:',
|
||||||
|
'slashes': true,
|
||||||
|
'host': '[fe80::1]',
|
||||||
|
'hostname': 'fe80::1',
|
||||||
|
'href': 'http://[fe80::1]/a/b?a=b#abc',
|
||||||
|
'search': '?a=b',
|
||||||
|
'query': 'a=b',
|
||||||
|
'hash': '#abc',
|
||||||
|
'pathname': '/a/b',
|
||||||
|
'path': '/a/b?a=b'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user