Skip to content

Commit

Permalink
Allow for double hyphens in isURL, closes #294
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Jun 13, 2014
1 parent 1f4c690 commit f860503
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe('Validators', function () {
, 'http://foobar.com#baz=qux'
, 'http://www.xn--froschgrn-x9a.net/'
, 'http://xn--froschgrn-x9a.com/'
, 'http://foo--bar.com'
]
, invalid: [
'xyz://foobar.com'
Expand All @@ -94,11 +95,12 @@ describe('Validators', function () {
, 'rtmp://foobar.com'
, 'http://www.xn--.com/'
, 'http://xn--.com/'
, 'http://www.xn--foo--bar.com/'
, 'http://xn--foo--bar.com/'
, 'http://www.foobar.com:0/'
, 'http://www.foobar.com:70000/'
, 'http://www.foobar.com:99999/'
, 'http://www.-foobar.com/'
, 'http://www.foobar-.com/'
, 'http://www.foo---bar.com/'
, ''
, 'http://foobar.com/' + new Array(2083).join('f')
]
Expand Down
2 changes: 1 addition & 1 deletion validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
return false;
}
options = merge(options, default_url_options);
var url = new RegExp('^(?!mailto:)(?:(?:' + options.protocols.join('|') + ')://)' + (options.require_protocol ? '' : '?') + '(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:www.)?xn--)?(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))' + (options.require_tld ? '' : '?') + ')|localhost)(?::(\\d{1,5}))?(?:(?:/|\\?|#)[^\\s]*)?$', 'i');
var url = new RegExp('^(?!mailto:)(?:(?:' + options.protocols.join('|') + ')://)' + (options.require_protocol ? '' : '?') + '(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:www.)?)?(?:(?:[a-z\\u00a1-\\uffff0-9]+-?-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))' + (options.require_tld ? '' : '?') + ')|localhost)(?::(\\d{1,5}))?(?:(?:/|\\?|#)[^\\s]*)?$', 'i');
var match = str.match(url)
, port = match ? match[1] : 0;
return !!(match && (!port || (port > 0 && port <= 65535)));
Expand Down

0 comments on commit f860503

Please sign in to comment.