Skip to content

Commit

Permalink
Merge pull request #807 from vodolaz095/yandex_normalize_dedup
Browse files Browse the repository at this point in the history
added normalisation for yandex based emails
  • Loading branch information
chriso authored May 3, 2018
2 parents 3f5e506 + f96ccb5 commit 5e2cf36
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
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) {
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.

0 comments on commit 5e2cf36

Please sign in to comment.