From dcecfc5f1b417c5e06a8430143ccd9da17a6ae34 Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 19 Jul 2011 09:55:01 -0700 Subject: [PATCH] Close #1360 url: Allow _ in hostnames. --- lib/url.js | 6 +++--- test/simple/test-url.js | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/url.js b/lib/url.js index a30fa8a9cf..e4fcf779fa 100644 --- a/lib/url.js +++ b/lib/url.js @@ -46,8 +46,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-zA-Z0-9][a-z0-9A-Z_-]{0,62}$/, + hostnamePartStart = /^([a-zA-Z0-9][a-z0-9A-Z_-]{0,62})(.*)$/, // protocols that can allow "unsafe" and "unwise" chars. unsafeProtocol = { 'javascript': true, @@ -226,7 +226,7 @@ function urlParse(url, parseQueryString, slashesDenoteHost) { var newOut = []; for (var i = 0; i < domainArray.length; ++i) { var s = domainArray[i]; - newOut.push(s.match(/[^A-Za-z0-9-]/) ? + newOut.push(s.match(/[^A-Za-z0-9_-]/) ? 'xn--' + punycode.encode(s) : s); } out.hostname = newOut.join('.'); diff --git a/test/simple/test-url.js b/test/simple/test-url.js index f07edb5cd4..fdf8bde596 100644 --- a/test/simple/test-url.js +++ b/test/simple/test-url.js @@ -327,8 +327,17 @@ var parseTests = { 'host': 'xn--hgi.ws', 'hostname': 'xn--hgi.ws', 'pathname': '/➡' + }, + 'http://bucket_name.s3.amazonaws.com/image.jpg': { + protocol: 'http:', + slashes: true, + host: 'bucket_name.s3.amazonaws.com', + hostname: 'bucket_name.s3.amazonaws.com', + pathname: '/image.jpg', + href: 'http://bucket_name.s3.amazonaws.com/image.jpg' } }; + for (var u in parseTests) { var actual = url.parse(u), expected = parseTests[u];