Skip to content

Commit

Permalink
fix: hard coded yandex domain conversion (validatorjs#2441)
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushGH authored Aug 24, 2024
1 parent 72c4674 commit f2b1082
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/normalizeEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const default_normalize_email_options = {
// The following conversions are specific to Yandex
// Lowercases the local part of the Yandex address (known to be case-insensitive)
yandex_lowercase: true,
// all yandex domains are equal, this explicitly sets the domain to 'yandex.ru'
yandex_convert_yandexru: true,

// The following conversions are specific to iCloud
// Lowercases the local part of the iCloud address (known to be case-insensitive)
Expand Down Expand Up @@ -232,7 +234,7 @@ export default function normalizeEmail(email, options) {
if (options.all_lowercase || options.yandex_lowercase) {
parts[0] = parts[0].toLowerCase();
}
parts[1] = 'yandex.ru'; // all yandex domains are equal, 1st preferred
parts[1] = options.yandex_convert_yandexru ? 'yandex.ru' : parts[1];
} else if (options.all_lowercase) {
// Any other address
parts[0] = parts[0].toLowerCase();
Expand Down
29 changes: 29 additions & 0 deletions test/sanitizers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,5 +481,34 @@ describe('Sanitizers', () => {
'[email protected]': '[email protected]',
},
});

// Testing yandex_convert_yandexru
test({
sanitizer: 'normalizeEmail',
args: [{
yandex_convert_yandexru: false,
}],
expect: {
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
},
});

test({
sanitizer: 'normalizeEmail',
args: [{
yandex_convert_yandexru: true,
}],
expect: {
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
'[email protected]': '[email protected]',
},
});
});
});

0 comments on commit f2b1082

Please sign in to comment.