Skip to content

Commit

Permalink
isURL - email addresses validate as URLs validatorjs#707
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingNagger committed Oct 2, 2018
1 parent 5d3fac0 commit 87b43c5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/isURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ function isURL(url, options) {

split = url.split('@');
if (split.length > 1) {
if (options.exclude_auth_url) {
return false;
}
auth = split.shift();
if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
return false;
Expand Down
3 changes: 3 additions & 0 deletions src/lib/isURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export default function isURL(url, options) {

split = url.split('@');
if (split.length > 1) {
if (options.exclude_auth_url) {
return false;
}
auth = split.shift();
if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
return false;
Expand Down
14 changes: 14 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,20 @@ describe('Validators', () => {
});
});

it('should allow rejecting urls containing authentication information', () => {
test({
validator: 'isURL',
args: [{ exclude_auth_url: true }],
valid: [
'doe.com',
],
invalid: [
'john@doe.com',
'john:john@doe.com',
],
});
});

it('should validate MAC addresses', () => {
test({
validator: 'isMACAddress',
Expand Down
3 changes: 3 additions & 0 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ function isURL(url, options) {

split = url.split('@');
if (split.length > 1) {
if (options.exclude_auth_url) {
return false;
}
auth = split.shift();
if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit 87b43c5

Please sign in to comment.