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

Make email validator case-insensitive #35790

Merged
merged 6 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ko.validation.rules['emailRFC2822'] = {
validator: function (val) {
if (val === undefined || val.length === 0) {return true;} // do separate validation for required
var re = /(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/;
var re = /(?:[A-Za-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[A-Za-z0-9-]*[A-Za-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/;

Check failure on line 12 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap3/validators.ko.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

Unexpected control character(s) in regular expression: \x01, \x08, \x0b, \x0c, \x0e, \x1f, \x01, \x09, \x0b, \x0c, \x0e, \x01, \x08, \x0b, \x0c, \x0e, \x1f, \x01, \x09, \x0b, \x0c, \x0e

Check failure on line 12 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap3/validators.ko.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

Unnecessary escape character: \/

Check failure on line 12 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap3/validators.ko.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

Unnecessary escape character: \/
return re.test(val || '') && val.indexOf(' ') < 0;
},
message: gettext("Not a valid email"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ko.validation.rules['emailRFC2822'] = {
validator: function (val) {
if (val === undefined || val.length === 0) {return true;} // do separate validation for required
var re = /(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/;
var re = /(?:[A-Za-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[A-Za-z0-9-]*[A-Za-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/;

Check failure on line 19 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap5/validators.ko.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

Unexpected control character(s) in regular expression: \x01, \x08, \x0b, \x0c, \x0e, \x1f, \x01, \x09, \x0b, \x0c, \x0e, \x01, \x08, \x0b, \x0c, \x0e, \x1f, \x01, \x09, \x0b, \x0c, \x0e

Check failure on line 19 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap5/validators.ko.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

Unnecessary escape character: \/

Check failure on line 19 in corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap5/validators.ko.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

Unnecessary escape character: \/
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively, you could run test on value.toLowerCase() and make the regex a smidge simpler. But it's already a monstrosity, so this is just a suggestion.

return re.test(val || '') && val.indexOf(' ') < 0;
},
message: gettext("Not a valid email"),
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/registration/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ def __init__(self, data=None, is_add_user=None,
)

def clean_email(self):
email = self.cleaned_data['email'].strip()
email = self.cleaned_data['email'].strip().lower()

from corehq.apps.registration.validation import AdminInvitesUserFormValidator
error = AdminInvitesUserFormValidator.validate_email(self.domain, email, bool(self.invite))
Expand Down
Loading