Browse Source

url: parse hostnames that start with - or _

Allow hostnames like '-lovemonsterz.tumblr.com' and '_jabber._tcp.google.com'.

Fixes #4177.
v0.8.13-release
Ben Noordhuis 12 years ago
parent
commit
de0303d3ad
  1. 4
      lib/url.js
  2. 91
      test/simple/test-url.js

4
lib/url.js

@ -50,8 +50,8 @@ var protocolPattern = /^([a-z0-9.+-]+:)/i,
.concat(unwise).concat(autoEscape),
nonAuthChars = ['/', '@', '?', '#'].concat(delims),
hostnameMaxLen = 255,
hostnamePartPattern = /^[a-zA-Z0-9][a-z0-9A-Z_-]{0,62}$/,
hostnamePartStart = /^([a-zA-Z0-9][a-z0-9A-Z_-]{0,62})(.*)$/,
hostnamePartPattern = /^[a-z0-9A-Z_-]{0,63}$/,
hostnamePartStart = /^([a-z0-9A-Z_-]{0,63})(.*)$/,
// protocols that can allow "unsafe" and "unwise" chars.
unsafeProtocol = {
'javascript': true,

91
test/simple/test-url.js

@ -651,7 +651,96 @@ var parseTests = {
'hash': '#abc',
'pathname': '/a/b',
'path': '/a/b?a=b'
}
},
'http://-lovemonsterz.tumblr.com/rss': {
'protocol': 'http:',
'slashes': true,
'host': '-lovemonsterz.tumblr.com',
'hostname': '-lovemonsterz.tumblr.com',
'href': 'http://-lovemonsterz.tumblr.com/rss',
'pathname': '/rss',
'path': '/rss',
},
'http://-lovemonsterz.tumblr.com:80/rss': {
'protocol': 'http:',
'slashes': true,
'port': '80',
'host': '-lovemonsterz.tumblr.com:80',
'hostname': '-lovemonsterz.tumblr.com',
'href': 'http://-lovemonsterz.tumblr.com:80/rss',
'pathname': '/rss',
'path': '/rss',
},
'http://user:pass@-lovemonsterz.tumblr.com/rss': {
'protocol': 'http:',
'slashes': true,
'auth': 'user:pass',
'host': '-lovemonsterz.tumblr.com',
'hostname': '-lovemonsterz.tumblr.com',
'href': 'http://user:pass@-lovemonsterz.tumblr.com/rss',
'pathname': '/rss',
'path': '/rss',
},
'http://user:pass@-lovemonsterz.tumblr.com:80/rss': {
'protocol': 'http:',
'slashes': true,
'auth': 'user:pass',
'port': '80',
'host': '-lovemonsterz.tumblr.com:80',
'hostname': '-lovemonsterz.tumblr.com',
'href': 'http://user:pass@-lovemonsterz.tumblr.com:80/rss',
'pathname': '/rss',
'path': '/rss',
},
'http://_jabber._tcp.google.com/test': {
'protocol': 'http:',
'slashes': true,
'host': '_jabber._tcp.google.com',
'hostname': '_jabber._tcp.google.com',
'href': 'http://_jabber._tcp.google.com/test',
'pathname': '/test',
'path': '/test',
},
'http://user:pass@_jabber._tcp.google.com/test': {
'protocol': 'http:',
'slashes': true,
'auth': 'user:pass',
'host': '_jabber._tcp.google.com',
'hostname': '_jabber._tcp.google.com',
'href': 'http://user:pass@_jabber._tcp.google.com/test',
'pathname': '/test',
'path': '/test',
},
'http://_jabber._tcp.google.com:80/test': {
'protocol': 'http:',
'slashes': true,
'port': '80',
'host': '_jabber._tcp.google.com:80',
'hostname': '_jabber._tcp.google.com',
'href': 'http://_jabber._tcp.google.com:80/test',
'pathname': '/test',
'path': '/test',
},
'http://user:pass@_jabber._tcp.google.com:80/test': {
'protocol': 'http:',
'slashes': true,
'auth': 'user:pass',
'port': '80',
'host': '_jabber._tcp.google.com:80',
'hostname': '_jabber._tcp.google.com',
'href': 'http://user:pass@_jabber._tcp.google.com:80/test',
'pathname': '/test',
'path': '/test',
},
};
for (var u in parseTests) {

Loading…
Cancel
Save