Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ignore an empty port component when parsing URLs.

  • Loading branch information...
commit 677c2c112c8f92910b85e14575c9c941799f5916 1 parent a10cfba
@morkai morkai authored isaacs committed
Showing with 56 additions and 2 deletions.
  1. +4 −2 lib/url.js
  2. +52 −0 test/simple/test-url.js
View
6 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];
- out.port = port.substr(1);
+ if (port !== ':') {
+ out.port = port.substr(1);
+ }
host = host.substr(0, host.length - port.length);
}
if (host) out.hostname = host;
View
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'
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.