Skip to content

Commit

Permalink
fix(isEmail): respect ignore_max_length option (#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

2 comments on commit 2a80c34

@jaoaustero
Copy link

@jaoaustero jaoaustero commented on 2a80c34 Sep 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even the ignore_max_length to true it still return a false, I got version 13.1.17.

Implementation that I have

import isEmail from 'validator/es/lib/isEmail';

const value = 'Deleted-user-id-19430-Team-5051deleted-user-id-19430-team-5051XXXXXX@example.com';
isEmail(value, {ignore_max_length : true})

@profnandaa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not yet out, it's queued up for our next release.

Please sign in to comment.