You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
normalizeEmail currently starts by calling isEmail. This might make sense as a guard, but there is currently no way to pass in options, which may result in false negatives for people who make use of the options, particularly require_tld. Additionally it's simply not obvious that normalizeEmail also validates unless you look at the code; this might be resulting in people doing unnecessary double validations.
I can see a few ways to solve this:
Allow passing in additional options for the isEmail call, and clearly document that this is a "2-in-1" function.
Pass in the most permissive set of options, i.e. { allow_display_name: true, require_display_name: false, allow_utf8_local_part: true, require_tld: false }, and let the user handle any more restrictive validation beforehand.
Remove the isEmail call altogether and let the user handle any validation beforehand. Or provide an option to do so. This is my preference because I think that normalizeEmail should only be responsible for one thing.
Display name support might need to be added if it's desired.
Actually I ran across this because I'm primarily using Joi for validation in a Node app (just because it is schema-based and has structured errors built-in), but I'm also using this library for the email normalization (among other things). I found email addresses like "whatever@local" that passed with Joi's defaults (refer to this) weren't passing normalizeEmail's check. isEmail has the require_tld: false option that would fix this, but there's no way to pass it through. As a workaround, Joi has a similar option minDomainAtoms which can be set to 2 to better match this library's default behavior, but it's still a workaround... as a general principle I'd rather just not have (restrictive) validation unless I ask for it.
The text was updated successfully, but these errors were encountered:
normalizeEmail
currently starts by callingisEmail
. This might make sense as a guard, but there is currently no way to pass in options, which may result in false negatives for people who make use of the options, particularlyrequire_tld
. Additionally it's simply not obvious thatnormalizeEmail
also validates unless you look at the code; this might be resulting in people doing unnecessary double validations.I can see a few ways to solve this:
Allow passing in additional options for the
isEmail
call, and clearly document that this is a "2-in-1" function.Pass in the most permissive set of options, i.e.
{ allow_display_name: true, require_display_name: false, allow_utf8_local_part: true, require_tld: false }
, and let the user handle any more restrictive validation beforehand.Remove the
isEmail
call altogether and let the user handle any validation beforehand. Or provide an option to do so. This is my preference because I think thatnormalizeEmail
should only be responsible for one thing.Display name support might need to be added if it's desired.
Actually I ran across this because I'm primarily using Joi for validation in a Node app (just because it is schema-based and has structured errors built-in), but I'm also using this library for the email normalization (among other things). I found email addresses like "whatever@local" that passed with Joi's defaults (refer to this) weren't passing
normalizeEmail
's check.isEmail
has therequire_tld: false
option that would fix this, but there's no way to pass it through. As a workaround, Joi has a similar optionminDomainAtoms
which can be set to2
to better match this library's default behavior, but it's still a workaround... as a general principle I'd rather just not have (restrictive) validation unless I ask for it.The text was updated successfully, but these errors were encountered: