Skip to content

Commit

Permalink
Put length restrictions on email parts, re #258
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Aug 3, 2015
1 parent 09f0c6d commit 919e371
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ function test(options) {
}
}

function repeat(str, count) {
var result = '';
while (count--) {
result += str;
}
return result;
}

describe('Validators', function () {

it('should validate email addresses', function () {
Expand All @@ -51,6 +59,7 @@ describe('Validators', function () {
, '"foobar"@example.com'
, '" foo m端ller "@example.com'
, '"foo\\@bar"@example.com'
, repeat('a', 64) + '@' + repeat('a', 252) + '.com'
]
, invalid: [
'invalidemail@'
Expand All @@ -60,6 +69,9 @@ describe('Validators', function () {
, 'somename@gmail.com'
, '[email protected].'
, '[email protected]'
, 'gmailgmailgmailgmailgmail@gmail.com'
, repeat('a', 64) + '@' + repeat('a', 253) + '.com'
, repeat('a', 65) + '@' + repeat('a', 252) + '.com'
]
});
});
Expand Down
5 changes: 5 additions & 0 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@
user = user.replace(/\./g, '').toLowerCase();
}

if (!validator.isByteLength(user, 0, 64) ||
!validator.isByteLength(domain, 0, 256)) {
return false;
}

if (!validator.isFQDN(domain, {require_tld: options.require_tld})) {
return false;
}
Expand Down
Loading

0 comments on commit 919e371

Please sign in to comment.