Skip to content

Commit

Permalink
Don't whitelist localhost, closes #675
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Jul 7, 2017
1 parent 4f10904 commit cc96615
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#### HEAD

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

#### 7.2.0

- Added an option to validate any phone locale
Expand Down
2 changes: 1 addition & 1 deletion lib/isURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function isURL(url, options) {
}
}

if (!(0, _isIP2.default)(host) && !(0, _isFQDN2.default)(host, options) && (!ipv6 || !(0, _isIP2.default)(ipv6, 6)) && host !== 'localhost') {
if (!(0, _isIP2.default)(host) && !(0, _isFQDN2.default)(host, options) && (!ipv6 || !(0, _isIP2.default)(ipv6, 6))) {
return false;
}

Expand Down
3 changes: 1 addition & 2 deletions src/lib/isURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ export default function isURL(url, options) {
}
}

if (!isIP(host) && !isFQDN(host, options) && (!ipv6 || !isIP(ipv6, 6)) &&
host !== 'localhost') {
if (!isIP(host) && !isFQDN(host, options) && (!ipv6 || !isIP(ipv6, 6))) {
return false;
}

Expand Down
6 changes: 4 additions & 2 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ describe('Validators', function () {
'http://189.123.14.13/',
'http://duckduckgo.com/?q=%2F',
'http://foobar.com/t$-_.+!*\'(),',
'http://localhost:3000/',
'http://foobar.com/?foo=bar#baz=qux',
'http://foobar.com?foo=bar',
'http://foobar.com#baz=qux',
Expand All @@ -255,6 +254,7 @@ describe('Validators', function () {
'http://[2010:836B:4179::836B:4179]',
],
invalid: [
'http://localhost:3000/',
'xyz://foobar.com',
'invalid/',
'invalid.x',
Expand Down Expand Up @@ -316,6 +316,7 @@ describe('Validators', function () {
args: [{
protocols: ['file'],
require_host: false,
require_tld: false,
}],
valid: [
'file://localhost/foo.txt',
Expand Down Expand Up @@ -369,6 +370,7 @@ describe('Validators', function () {
valid: [
'http://foobar.com/',
'http://foobar/',
'http://localhost/',
'foobar/',
'foobar',
],
Expand Down Expand Up @@ -437,9 +439,9 @@ describe('Validators', function () {
}],
valid: [
'http://foobar.com/',
'http://localhost/',
],
invalid: [
'http://localhost/',
'foobar.com',
'foobar',
],
Expand Down
2 changes: 1 addition & 1 deletion validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ function isURL(url, options) {
}
}

if (!isIP(host) && !isFDQN(host, options) && (!ipv6 || !isIP(ipv6, 6)) && host !== 'localhost') {
if (!isIP(host) && !isFDQN(host, options) && (!ipv6 || !isIP(ipv6, 6))) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit cc96615

Please sign in to comment.