-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35790 from dimagi/em/email-validator-case-sensiti…
…vity Make email validator case-insensitive
- Loading branch information
Showing
9 changed files
with
104 additions
and
9 deletions.
There are no files selected for viewing
4 changes: 3 additions & 1 deletion
4
corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap3/validators.ko.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
hqDefine("hqwebapp/js/constants", [], function () { | ||
return { | ||
// eslint-disable-next-line no-control-regex | ||
EMAIL_VALIDATION_REGEX: /(?:[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])+)\])$/, | ||
}; | ||
}); |
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))); | ||
}); | ||
}); | ||
}); |
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
4 changes: 2 additions & 2 deletions
4
corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/javascript/hqwebapp/spec/main.js.diff.txt
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