Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Support Unicode international characters #151

Merged
merged 15 commits into from
Feb 15, 2017
Merged
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,19 @@ internals.regex = {
ipV6: /^[a-fA-F\d]{0,4}$/
};

// $lab:coverage:off$
internals.nulNormalize = function (email) {

let emailPieces = email.split('\u0000');
emailPieces = emailPieces.map((string) => {

return string.normalize('NFC');
});

return emailPieces.join('\u0000');
};
// $lab:coverage:on$


internals.checkIpV6 = function (items) {

Expand Down Expand Up @@ -1413,5 +1426,12 @@ exports.diagnoses = internals.validate.diagnoses = (function () {

exports.normalize = internals.normalize = function (email) {

// $lab:coverage:off$
if (process.version[1] === '4' && email.match(/\0/g)) {
Copy link

@lamchakchan lamchakchan Feb 10, 2017

Choose a reason for hiding this comment

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

I would recommend replacing regex with a simple indexOf for performance reasons.

if (process.version[1] === '4' && email.indexOf('\u0000') === 0) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On it. Just haven't pushed up yet :)
Also, using email.indexOf('/u0000') >= 0 because the NUL is not necessarily at the beginning

return internals.nulNormalize(email);
}
// $lab:coverage:on$


return email.normalize('NFC');
};