Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added normalisation for yandex based emails #807

Merged
merged 2 commits into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/normalizeEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ 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'];

// List of domains used by yandex.ru
var yandex_domains = ['yandex.ru', 'yandex.ua', 'yandex.kz', 'yandex.com', 'yandex.by', 'ya.ru'];

// replace single dots, but not multiple consecutive dots
function dotsReplacer(match) {
if (match.length > 1) {
Expand Down Expand Up @@ -129,6 +132,11 @@ function normalizeEmail(email, options) {
if (options.all_lowercase || options.yahoo_lowercase) {
parts[0] = parts[0].toLowerCase();
}
} else if (~yandex_domains.indexOf(parts[1])) {
if (options.all_lowercase || options.yahoo_lowercase) {
Copy link

Choose a reason for hiding this comment

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

Hi there! Thanks for the PR :)
I think it shouldn't use options.yahoo_lowercase because this option is for yahoo case only

parts[0] = parts[0].toLowerCase();
}
parts[1] = 'yandex.ru'; // all yandex domains are equal, 1st preffered
} else if (options.all_lowercase) {
// Any other address
parts[0] = parts[0].toLowerCase();
Expand Down
15 changes: 15 additions & 0 deletions src/lib/normalizeEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ const yahoo_domains = [
'ymail.com',
];

// List of domains used by yandex.ru
const yandex_domains = [
'yandex.ru',
'yandex.ua',
'yandex.kz',
'yandex.com',
'yandex.by',
'ya.ru',
];

// replace single dots, but not multiple consecutive dots
function dotsReplacer(match) {
if (match.length > 1) {
Expand Down Expand Up @@ -214,6 +224,11 @@ export default function normalizeEmail(email, options) {
if (options.all_lowercase || options.yahoo_lowercase) {
parts[0] = parts[0].toLowerCase();
}
} else if (~yandex_domains.indexOf(parts[1])) {
if (options.all_lowercase || options.yahoo_lowercase) {
parts[0] = parts[0].toLowerCase();
}
parts[1] = 'yandex.ru'; // all yandex domains are equal, 1st preffered
} else if (options.all_lowercase) {
// Any other address
parts[0] = parts[0].toLowerCase();
Expand Down
6 changes: 6 additions & 0 deletions test/sanitizers.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ describe('Sanitizers', function () {
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
'"foo@bar"@baz.com': '"foo@bar"@baz.com',
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
},
});

Expand Down
8 changes: 8 additions & 0 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,9 @@ 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'];

// List of domains used by yandex.ru
var yandex_domains = ['yandex.ru', 'yandex.ua', 'yandex.kz', 'yandex.com', 'yandex.by', 'ya.ru'];

// replace single dots, but not multiple consecutive dots
function dotsReplacer(match) {
if (match.length > 1) {
Expand Down Expand Up @@ -1525,6 +1528,11 @@ function normalizeEmail(email, options) {
if (options.all_lowercase || options.yahoo_lowercase) {
parts[0] = parts[0].toLowerCase();
}
} else if (~yandex_domains.indexOf(parts[1])) {
if (options.all_lowercase || options.yahoo_lowercase) {
parts[0] = parts[0].toLowerCase();
}
parts[1] = 'yandex.ru'; // all yandex domains are equal, 1st preffered
} else if (options.all_lowercase) {
// Any other address
parts[0] = parts[0].toLowerCase();
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.