-
-
Notifications
You must be signed in to change notification settings - Fork 222
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
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d6b66ee
Make email validator case-insensitive
nospame b76e8d0
Lowercase new web user email before validating
nospame e92b8b3
Lint email validation regex
nospame c39df56
Move email validation regex to constants
nospame 453f37a
Add email_validator_spec
nospame bcbb8e7
"Bootstrap 5 Migration - Rebuilt diffs"
nospame File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
corehq/apps/hqwebapp/static/hqwebapp/spec/email_validator_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* eslint-env mocha */ | ||
hqDefine("hqwebapp/spec/email_validator_spec", [ | ||
'hqwebapp/js/constants', | ||
], function ( | ||
constants, | ||
) { | ||
describe('email_validator', function () { | ||
const re = constants.EMAIL_VALIDATION_REGEX; | ||
const testEmail = email => re.test(email); | ||
|
||
it('should allow simple email addresses', function () { | ||
assert.ok(testEmail('[email protected]')); | ||
}); | ||
|
||
it('should allow capital letters in the local part', function () { | ||
assert.ok(testEmail('[email protected]')); | ||
assert.ok(testEmail('[email protected]')); | ||
}); | ||
|
||
it('should allow capital letters in the domain part', function () { | ||
assert.ok(testEmail('[email protected]')); | ||
assert.ok(testEmail('[email protected]')); | ||
}); | ||
|
||
it('should allow digits in the local part', function () { | ||
assert.ok(testEmail('[email protected]')); | ||
}); | ||
|
||
it('should allow specified special characters in the local part', function () { | ||
assert.ok(testEmail('.\x01!#$%&"\'*+/=?^_`{|}[email protected]')); | ||
}); | ||
|
||
it('should allow subdomains', function () { | ||
assert.ok(testEmail('[email protected]')); | ||
}); | ||
|
||
it('should allow hyphens in domain names', function () { | ||
assert.ok(testEmail('[email protected]')); | ||
}); | ||
|
||
it('should allow IP addresses in brackets as the domain', function () { | ||
assert.ok(testEmail('whosaidthiswasok@[127.0.0.1]')); | ||
}); | ||
|
||
it('should reject missing @ symbol', function () { | ||
assert.notOk(testEmail('notanemail')); | ||
}); | ||
|
||
it('should reject missing local part', function () { | ||
assert.notOk(testEmail('@example.com')); | ||
}); | ||
|
||
it('should reject missing top-level domain', function () { | ||
assert.notOk(testEmail('nothing@toseehere')); | ||
assert.notOk(testEmail('noteven@toseehere.')); | ||
}); | ||
|
||
it('should reject invalid characters in the domain part', function () { | ||
const emails = [ | ||
// allowed in local part but not domain | ||
'me@ex\x01ample.com', | ||
'me@ex!ample.com', | ||
'me@ex#ample.com', | ||
'me@ex$ample.com', | ||
'me@ex%ample.com', | ||
'me@ex&le.com', | ||
'me@ex"ample.com', | ||
'me@ex\'ample.com', | ||
'me@ex*ample.com', | ||
'me@ex+ample.com', | ||
'me@ex/ample.com', | ||
'me@ex=ample.com', | ||
'me@ex?ample.com', | ||
'me@ex^ample.com', | ||
'me@ex_ample.com', | ||
'me@ex`ample.com', | ||
'me@ex{ample}.com', | ||
'me@ex|ample.com', | ||
]; | ||
emails.forEach(email => assert.notOk(testEmail(email))); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wild
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed! I think this is one of the places where, strictly speaking, some of these characters should only be allowed based on context rather than all the time, e.g. a quote should always be paired. But the existing expression doesn't test for that.