Skip to content
This repository was archived by the owner on Nov 15, 2017. It is now read-only.

Commit 608e5e0

Browse files
committed
naive ip address test too naive, i.e. "ca" was reported as an IP address
1 parent 33980b3 commit 608e5e0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

js/uritools.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var reIPv6FromAuthority = /^(?:[^@]*@)?(\[[0-9a-f:]+\])(?::\d*)?$/i;
6565

6666
// Coarse (but fast) tests
6767
var reValidHostname = /^([a-z\d]+(-*[a-z\d]+)*)(\.[a-z\d]+(-*[a-z\d])*)*$/;
68-
var reNotAnIPAddress = /[^\dA-Fa-f.:]/;
68+
var reIPAddressNaive = /^\d+\.\d+\.\d+\.\d+$|^\[[\da-zA-Z:]+\]$/;
6969

7070
// Accurate tests
7171
// Source.: http://stackoverflow.com/questions/5284147/validating-ipv4-addresses-with-regexp/5284410#5284410
@@ -277,7 +277,7 @@ URI.hostnameFromURI = function(uri) {
277277
var psl = publicSuffixList;
278278

279279
URI.domainFromHostname = function(hostname) {
280-
if ( reNotAnIPAddress.test(hostname) ) {
280+
if ( !reIPAddressNaive.test(hostname) ) {
281281
return psl.getDomain(hostname);
282282
}
283283
return hostname;

0 commit comments

Comments
 (0)