Skip to content

Commit

Permalink
fix(isEmail): respect ignore_max_length option (validatorjs#1435)
Browse files Browse the repository at this point in the history
* Do not validate the length of email parts if ignore_max_length is true

* fix missing comma
  • Loading branch information
evantahler authored Sep 18, 2020
1 parent 0a5a20a commit 2a80c34
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib/isEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const default_email_options = {
require_display_name: false,
allow_utf8_local_part: true,
require_tld: true,
ignore_max_length: false,
};

/* eslint-disable max-len */
Expand Down Expand Up @@ -118,8 +119,10 @@ export default function isEmail(str, options) {
}
}

if (!isByteLength(user, { max: 64 }) ||
!isByteLength(domain, { max: 254 })) {
if (options.ignore_max_length === false && (
!isByteLength(user, { max: 64 }) ||
!isByteLength(domain, { max: 254 }))
) {
return false;
}

Expand Down
20 changes: 20 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,26 @@ describe('Validators', () => {
});
});

it('should validate really long emails if ignore_max_length is set', () => {
test({
validator: 'isEmail',
args: [{ ignore_max_length: false }],
valid: [],
invalid: [
'Deleted-user-id-19430-Team-5051deleted-user-id-19430-team-5051XXXXXX@example.com',
],
});

test({
validator: 'isEmail',
args: [{ ignore_max_length: true }],
valid: [
'Deleted-user-id-19430-Team-5051deleted-user-id-19430-team-5051XXXXXX@example.com',
],
invalid: [],
});
});

it('should validate URLs', () => {
test({
validator: 'isURL',
Expand Down

0 comments on commit 2a80c34

Please sign in to comment.