Skip to content

Commit

Permalink
feat: in email validator, block Intranet email address user@server1 a…
Browse files Browse the repository at this point in the history
…s it's rarely used nowadays
  • Loading branch information
3cp committed Jul 24, 2018
1 parent 340db0d commit 5104bce
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/standard-validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ export function config (validation) {
]);

// email regex from https://html.spec.whatwg.org/multipage/forms.html#valid-e-mail-address
validation.addValidator("email", {validate: "isTrue", value: /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,
// updated to block Intranet email address user@server1 as it's rarely used nowadays
validation.addValidator("email", {validate: "isTrue", value: /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/,
message: "not a valid email"});

// unique. need to access neighbours
Expand Down
1 change: 1 addition & 0 deletions test/standard-transformers-and-validators/email.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test('email: tests email', t => {
// shortcut
rule = {a: "email"};
t.deepEqual(v.validate({a: 'c'}, rule), {a: ["not a valid email"]});
t.deepEqual(v.validate({a: 'ab@test'}, rule), {a: ["not a valid email"]});
t.equal(v.validate({a: 'ab@test.com'}, rule), undefined);
t.end();
});

0 comments on commit 5104bce

Please sign in to comment.