Skip to content

Commit

Permalink
Reject URLs that are protocol only, closes #642
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Jul 7, 2017
1 parent cc96615 commit fdea1d7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- `isURL()` now requires the `require_tld: false` option to validate `localhost`
([#675](https://github.com/chriso/validator.js/issues/675))
- `isURL()` now rejects URLs that are protocol only
([#642](https://github.com/chriso/validator.js/issues/642))

#### 7.2.0

Expand Down
4 changes: 4 additions & 0 deletions lib/isURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ function isURL(url, options) {
}
url = split.join('://');

if (url === '') {
return false;
}

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

Expand Down
4 changes: 4 additions & 0 deletions src/lib/isURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export default function isURL(url, options) {
}
url = split.join('://');

if (url === '') {
return false;
}

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 @@ -325,6 +325,7 @@ describe('Validators', function () {
],
invalid: [
'http://foobar.com',
'file://',
],
});
});
Expand Down
4 changes: 4 additions & 0 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ function isURL(url, options) {
}
url = split.join('://');

if (url === '') {
return false;
}

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 fdea1d7

Please sign in to comment.