Skip to content

Commit

Permalink
Merge pull request #873 from chriso/chriso/domain-specific-validation…
Browse files Browse the repository at this point in the history
…-flag

Domain specific email validation flag
  • Loading branch information
chriso authored Jul 31, 2018
2 parents f0151fa + 6030805 commit e027403
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 44 deletions.
2 changes: 1 addition & 1 deletion lib/isEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function isEmail(str, options) {

var lower_domain = domain.toLowerCase();

if (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com') {
if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) {
/*
Previously we removed dots for gmail addresses before validating.
This was removed because it allows `multiple..dots@gmail.com`
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function isEmail(str, options) {

const lower_domain = domain.toLowerCase();

if (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com') {
if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) {
/*
Previously we removed dots for gmail addresses before validating.
This was removed because it allows `multiple..dots@gmail.com`
Expand Down
62 changes: 22 additions & 40 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ describe('Validators', () => {
`${repeat('a', 64)}@${repeat('a', 63)}.com`,
`${repeat('a', 64)}@${repeat('a', 63)}.${repeat('a', 63)}.${repeat('a', 63)}.${repeat('a', 58)}.com`,
`${repeat('a', 64)}@${repeat('a', 63)}.com`,
`${repeat('a', 31)}@gmail.com`,
'test@gmail.com',
'test.1@gmail.com',
],
invalid: [
'invalidemail@',
Expand All @@ -77,7 +80,6 @@ describe('Validators', () => {
`${repeat('a', 64)}@${repeat('a', 251)}.com`,
`${repeat('a', 65)}@${repeat('a', 250)}.com`,
`${repeat('a', 64)}@${repeat('a', 64)}.com`,
`${repeat('a', 31)}@gmail.com`,
'test1@invalid.co m',
'test2@invalid.co m',
'test3@invalid.co m',
Expand All @@ -91,19 +93,31 @@ describe('Validators', () => {
'test11@invalid.co m',
'test12@invalid.co m',
'test13@invalid.co m',
'multiple..dots@stillinvalid.com',
'test123+invalid! sub_address@gmail.com',
'gmail...ignores...dots...@gmail.com',
'test@gmail.com',
'test.1@gmail.com',
'ends.with.dot.@gmail.com',
'multiple..dots@gmail.com',
'multiple..dots@stillinvalid.com',
'test123+invalid! sub_address@gmail.com',
'email@0.0.0.256',
'email@26.0.0.256',
],
});
});

it('should validate email addresses with domain specific validation', () => {
test({
validator: 'isEmail',
args: [{ domain_specific_validation: true }],
valid: [
'foo@bar.com',
],
invalid: [
`${repeat('a', 31)}@gmail.com`,
'test@gmail.com',
'test.1@gmail.com',
],
});
});


it('should validate email addresses without UTF8 characters in local part', () => {
test({
validator: 'isEmail',
Expand Down Expand Up @@ -162,6 +176,7 @@ describe('Validators', () => {
'Some Middle Name <some.name.midd.leNa.me+extension@GoogleMail.com>',
'Name <some.name.midd.leNa.me+extension@GoogleMail.com>',
'Name<some.name.midd.leNa.me+extension@GoogleMail.com>',
'Some Name <foo@gmail.com>',
],
invalid: [
'invalidemail@',
Expand All @@ -179,7 +194,6 @@ describe('Validators', () => {
'Some Name < foo@bar.co.uk >',
'Name foo@bar.co.uk',
'Some Name <some..name@gmail.com>',
'Some Name <foo@gmail.com>',
],
});
});
Expand Down Expand Up @@ -239,38 +253,6 @@ describe('Validators', () => {
'email@255.255.255.255',
],
invalid: [
'invalidemail@',
'invalid.com',
'@invalid.com',
'foo@bar.com.',
'somename@gmail.com',
'foo@bar.co.uk.',
'z@co.c',
'gmailgmailgmailgmailgmail@gmail.com',
`${repeat('a', 64)}@${repeat('a', 251)}.com`,
`${repeat('a', 65)}@${repeat('a', 250)}.com`,
`${repeat('a', 64)}@${repeat('a', 64)}.com`,
`${repeat('a', 31)}@gmail.com`,
'test1@invalid.co m',
'test2@invalid.co m',
'test3@invalid.co m',
'test4@invalid.co m',
'test5@invalid.co m',
'test6@invalid.co m',
'test7@invalid.co m',
'test8@invalid.co m',
'test9@invalid.co m',
'test10@invalid.co m',
'test11@invalid.co m',
'test12@invalid.co m',
'test13@invalid.co m',
'gmail...ignores...dots...@gmail.com',
'test@gmail.com',
'test.1@gmail.com',
'ends.with.dot.@gmail.com',
'multiple..dots@gmail.com',
'multiple..dots@stillinvalid.com',
'test123+invalid! sub_address@gmail.com',
'email@0.0.0.256',
'email@26.0.0.256',
],
Expand Down
2 changes: 1 addition & 1 deletion validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function isEmail(str, options) {

var lower_domain = domain.toLowerCase();

if (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com') {
if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) {
/*
Previously we removed dots for gmail addresses before validating.
This was removed because it allows `multiple..dots@gmail.com`
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit e027403

Please sign in to comment.