Skip to content

Commit

Permalink
Fixed a bug with isURL()
Browse files Browse the repository at this point in the history
If the protocol was missing in a URL string and :// appeared in the
query string then the validator would incorrectly take anything up to
the :// as the protocol and would then fail.

This closes #518
  • Loading branch information
chriso committed Mar 30, 2016
1 parent f80ef02 commit 5af9a13
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#### HEAD

- Fixed a bug with `isURL()` when protocol was missing and :// appeared in the query
([#518](https://github.com/chriso/validator.js/issues/518))

#### 5.1.0

- Added a `unescape()` HTML function
Expand Down
12 changes: 7 additions & 5 deletions lib/isURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ function isURL(url, options) {
port = void 0,
port_str = void 0,
split = void 0;

split = url.split('#');
url = split.shift();

split = url.split('?');
url = split.shift();

split = url.split('://');
if (split.length > 1) {
protocol = split.shift();
Expand All @@ -61,11 +68,6 @@ function isURL(url, options) {
split[0] = url.substr(2);
}
url = split.join('://');
split = url.split('#');
url = split.shift();

split = url.split('?');
url = split.shift();

split = url.split('/');
url = split.shift();
Expand Down
12 changes: 7 additions & 5 deletions src/lib/isURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export default function isURL(url, options) {
}
options = merge(options, default_url_options);
let protocol, auth, host, hostname, port, port_str, split;

split = url.split('#');
url = split.shift();

split = url.split('?');
url = split.shift();

split = url.split('://');
if (split.length > 1) {
protocol = split.shift();
Expand All @@ -36,11 +43,6 @@ export default function isURL(url, options) {
split[0] = url.substr(2);
}
url = split.join('://');
split = url.split('#');
url = split.shift();

split = url.split('?');
url = split.shift();

split = url.split('/');
url = split.shift();
Expand Down
1 change: 1 addition & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ describe('Validators', function () {
'http://xn--j1aac5a4g.xn--j1amh',
'http://xn------eddceddeftq7bvv7c4ke4c.xn--p1ai',
'http://кулік.укр',
'test.com?ref=http://test2.com',
],
invalid: [
'xyz://foobar.com',
Expand Down
12 changes: 7 additions & 5 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,13 @@
port = void 0,
port_str = void 0,
split = void 0;

split = url.split('#');
url = split.shift();

split = url.split('?');
url = split.shift();

split = url.split('://');
if (split.length > 1) {
protocol = split.shift();
Expand All @@ -329,11 +336,6 @@
split[0] = url.substr(2);
}
url = split.join('://');
split = url.split('#');
url = split.shift();

split = url.split('?');
url = split.shift();

split = url.split('/');
url = split.shift();
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit 5af9a13

Please sign in to comment.