Browse Source

Ignore an empty port component when parsing URLs.

v0.9.1-release
Łukasz Walukiewicz 13 years ago
committed by isaacs
parent
commit
677c2c112c
  1. 4
      lib/url.js
  2. 52
      test/simple/test-url.js

4
lib/url.js

@ -31,7 +31,7 @@ exports.format = urlFormat;
// define these here so at least they only have to be
// compiled once on the first module load.
var protocolPattern = /^([a-z0-9.+-]+:)/i,
portPattern = /:[0-9]+$/,
portPattern = /:[0-9]*$/,
// RFC 2396: characters reserved for delimiting URLs.
delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
// RFC 2396: characters not allowed for various reasons.
@ -625,7 +625,9 @@ function parseHost(host) {
var port = portPattern.exec(host);
if (port) {
port = port[0];
if (port !== ':') {
out.port = port.substr(1);
}
host = host.substr(0, host.length - port.length);
}
if (host) out.hostname = host;

52
test/simple/test-url.js

@ -545,6 +545,58 @@ var parseTests = {
'query': 'n=Temperature',
'pathname': '/.well-known/r',
'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…
Cancel
Save