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

feat(normalizeEmail): optional yandex domain conversion #2441

Merged
merged 1 commit into from
Aug 24, 2024
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
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', () => {
'my.self@foo.com': 'my.self@foo.com',
},
});

// Testing yandex_convert_yandexru
test({
sanitizer: 'normalizeEmail',
args: [{
yandex_convert_yandexru: false,
}],
expect: {
'test@yandex.kz': 'test@yandex.kz',
'test@yandex.ru': 'test@yandex.ru',
'test@yandex.ua': 'test@yandex.ua',
'test@yandex.com': 'test@yandex.com',
'test@yandex.by': 'test@yandex.by',
},
});

test({
sanitizer: 'normalizeEmail',
args: [{
yandex_convert_yandexru: true,
}],
expect: {
'test@yandex.kz': 'test@yandex.ru',
'test@yandex.ru': 'test@yandex.ru',
'test@yandex.ua': 'test@yandex.ru',
'test@yandex.com': 'test@yandex.ru',
'test@yandex.by': 'test@yandex.ru',
},
});
});
});
Loading