Skip to content

Commit

Permalink
Merge pull request #820 from rathboma/gmail-dots
Browse files Browse the repository at this point in the history
Gmail - consecutive dots are not valid
  • Loading branch information
chriso authored May 3, 2018
2 parents e8eef94 + edb37a4 commit 80fb30d
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 9 deletions.
10 changes: 9 additions & 1 deletion lib/isEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,16 @@ function isEmail(str, options) {
var user = parts.join('@');

var lower_domain = domain.toLowerCase();

if (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com') {
user = user.replace(/\./g, '').toLowerCase();
/*
Previously we removed dots for gmail addresses before validating.
This was removed because it allows `[email protected]`
to be reported as valid, but it is not.
Gmail only normalizes single dots, removing them from here is pointless,
should be done in normalizeEmail
*/
user = user.toLowerCase();
}

if (!(0, _isByteLength2.default)(user, { max: 64 }) || !(0, _isByteLength2.default)(domain, { max: 254 })) {
Expand Down
11 changes: 10 additions & 1 deletion lib/normalizeEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ var outlookdotcom_domains = ['hotmail.at', 'hotmail.be', 'hotmail.ca', 'hotmail.
// This list is likely incomplete
var yahoo_domains = ['rocketmail.com', 'yahoo.ca', 'yahoo.co.uk', 'yahoo.com', 'yahoo.de', 'yahoo.fr', 'yahoo.in', 'yahoo.it', 'ymail.com'];

// replace single dots, but not multiple consecutive dots
function dotsReplacer(match) {
if (match.length > 1) {
return match;
}
return '';
}

function normalizeEmail(email, options) {
options = (0, _merge2.default)(options, default_normalize_email_options);

Expand All @@ -77,7 +85,8 @@ function normalizeEmail(email, options) {
parts[0] = parts[0].split('+')[0];
}
if (options.gmail_remove_dots) {
parts[0] = parts[0].replace(/\./g, '');
// this does not replace consecutive dots like example..email@gmail.com
parts[0] = parts[0].replace(/\.+/g, dotsReplacer);
}
if (!parts[0].length) {
return false;
Expand Down
10 changes: 9 additions & 1 deletion src/lib/isEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ export default function isEmail(str, options) {
let user = parts.join('@');

const lower_domain = domain.toLowerCase();

if (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com') {
user = user.replace(/\./g, '').toLowerCase();
/*
Previously we removed dots for gmail addresses before validating.
This was removed because it allows `[email protected]`
to be reported as valid, but it is not.
Gmail only normalizes single dots, removing them from here is pointless,
should be done in normalizeEmail
*/
user = user.toLowerCase();
}

if (!isByteLength(user, { max: 64 }) ||
Expand Down
11 changes: 10 additions & 1 deletion src/lib/normalizeEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ const yahoo_domains = [
'ymail.com',
];

// replace single dots, but not multiple consecutive dots
function dotsReplacer(match) {
if (match.length > 1) {
return match;
}
return '';
}

export default function normalizeEmail(email, options) {
options = merge(options, default_normalize_email_options);

Expand All @@ -162,7 +170,8 @@ export default function normalizeEmail(email, options) {
parts[0] = parts[0].split('+')[0];
}
if (options.gmail_remove_dots) {
parts[0] = parts[0].replace(/\./g, '');
// this does not replace consecutive dots like example..email@gmail.com
parts[0] = parts[0].replace(/\.+/g, dotsReplacer);
}
if (!parts[0].length) {
return false;
Expand Down
4 changes: 3 additions & 1 deletion test/sanitizers.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ describe('Sanitizers', function () {
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
'hans@m端ller.com': 'hans@m端ller.com',
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
'"foo@bar"@baz.com': '"foo@bar"@baz.com',
},
});
Expand Down Expand Up @@ -326,6 +327,7 @@ describe('Sanitizers', function () {
expect: {
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
},
});
Expand Down
5 changes: 4 additions & 1 deletion test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ describe('Validators', function () {
'test|123@m端ller.com',
'[email protected]',
'[email protected]',
'[email protected]',
'"foobar"@example.com',
'" foo m端ller "@example.com',
'"foo\\@bar"@example.com',
Expand Down Expand Up @@ -84,6 +83,9 @@ describe('Validators', function () {
'[email protected] m',
'[email protected] m',
'[email protected] m',
'[email protected]',
'[email protected]',
'[email protected]',
],
});
});
Expand Down Expand Up @@ -162,6 +164,7 @@ describe('Validators', function () {
'Some Name <[email protected].',
'Some Name < [email protected] >',
'Name [email protected]',
'Some Name <[email protected]>',
],
});
});
Expand Down
21 changes: 19 additions & 2 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,16 @@ function isEmail(str, options) {
var user = parts.join('@');

var lower_domain = domain.toLowerCase();

if (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com') {
user = user.replace(/\./g, '').toLowerCase();
/*
Previously we removed dots for gmail addresses before validating.
This was removed because it allows `[email protected]`
to be reported as valid, but it is not.
Gmail only normalizes single dots, removing them from here is pointless,
should be done in normalizeEmail
*/
user = user.toLowerCase();
}

if (!isByteLength(user, { max: 64 }) || !isByteLength(domain, { max: 254 })) {
Expand Down Expand Up @@ -1415,6 +1423,14 @@ var outlookdotcom_domains = ['hotmail.at', 'hotmail.be', 'hotmail.ca', 'hotmail.
// This list is likely incomplete
var yahoo_domains = ['rocketmail.com', 'yahoo.ca', 'yahoo.co.uk', 'yahoo.com', 'yahoo.de', 'yahoo.fr', 'yahoo.in', 'yahoo.it', 'ymail.com'];

// replace single dots, but not multiple consecutive dots
function dotsReplacer(match) {
if (match.length > 1) {
return match;
}
return '';
}

function normalizeEmail(email, options) {
options = merge(options, default_normalize_email_options);

Expand All @@ -1432,7 +1448,8 @@ function normalizeEmail(email, options) {
parts[0] = parts[0].split('+')[0];
}
if (options.gmail_remove_dots) {
parts[0] = parts[0].replace(/\./g, '');
// this does not replace consecutive dots like example..email@gmail.com
parts[0] = parts[0].replace(/\.+/g, dotsReplacer);
}
if (!parts[0].length) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit 80fb30d

Please sign in to comment.