From ddfc6b78cc15202789e58b9220c1897e9d9aa525 Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 19 Jul 2011 11:56:44 -0700 Subject: [PATCH] Close #1360 url: Allow _ in hostnames. --- lib/url.js | 4 ++-- test/simple/test-url.js | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/url.js b/lib/url.js index 8b01c8548f5bf7..6a26ed314b909d 100644 --- a/lib/url.js +++ b/lib/url.js @@ -44,8 +44,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, diff --git a/test/simple/test-url.js b/test/simple/test-url.js index ea85bc967fe2a3..8cee8eb2794d3f 100644 --- a/test/simple/test-url.js +++ b/test/simple/test-url.js @@ -274,8 +274,17 @@ var parseTests = { 'search' : '?search=foo', 'query' : 'search=foo', 'hash' : '#bar' + }, + '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];