From 2c3e5f81c648448824a1a79e9b72e3532d8caa4a Mon Sep 17 00:00:00 2001 From: vzaidman Date: Wed, 9 Aug 2017 17:21:04 +0300 Subject: [PATCH] added _ to the list of valid hostnames --- src/URI.js | 6 +++--- test/test.js | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/URI.js b/src/URI.js index 03f2c6c1..2420fb24 100644 --- a/src/URI.js +++ b/src/URI.js @@ -249,7 +249,7 @@ // allowed hostname characters according to RFC 3986 // ALPHA DIGIT "-" "." "_" "~" "!" "$" "&" "'" "(" ")" "*" "+" "," ";" "=" %encoded // I've never seen a (non-IDN) hostname other than: ALPHA DIGIT . - - URI.invalid_hostname_characters = /[^a-zA-Z0-9\.\-:]/; + URI.invalid_hostname_characters = /[^a-zA-Z0-9\.\-:_]/; // map DOM Elements to their URI attribute URI.domAttributes = { 'a': 'href', @@ -1044,10 +1044,10 @@ } else if (v && v.match(URI.invalid_hostname_characters)) { // test punycode if (!punycode) { - throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-] and Punycode.js is not available'); + throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-_] and Punycode.js is not available'); } if (punycode.toASCII(v).match(URI.invalid_hostname_characters)) { - throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.:-]'); + throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-_]'); } } }; diff --git a/test/test.js b/test/test.js index 8ebf8623..9a2be98f 100644 --- a/test/test.js +++ b/test/test.js @@ -124,6 +124,11 @@ ok(u instanceof URI, 'instanceof URI'); ok(u._parts.hostname !== undefined, 'host undefined'); }); + test('function URI(string) with complex hostname', function() { + var u = new URI('http://some.complex_host-name123.org/'); + ok(u instanceof URI, 'instanceof URI'); + ok(u._parts.hostname !== undefined, 'host undefined'); + }); test('function URI(string) with invalid port "port" throws', function () { raises(function () { new URI('http://example.org:port');