Skip to content

Commit

Permalink
added _ to the list of valid hostnames
Browse files Browse the repository at this point in the history
  • Loading branch information
vzaidman committed Aug 9, 2017
1 parent 8043e13 commit 2c3e5f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/URI.js
Expand Up @@ -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',
Expand Down Expand Up @@ -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.-_]');
}
}
};
Expand Down
5 changes: 5 additions & 0 deletions test/test.js
Expand Up @@ -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');
Expand Down

0 comments on commit 2c3e5f8

Please sign in to comment.