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 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import hqMocha from "mocha/js/main";

import "hqwebapp/spec/assert_properties_spec";
import "hqwebapp/spec/email_validator_spec";
import "hqwebapp/spec/bootstrap3/inactivity_spec";
import "hqwebapp/spec/urllib_spec";
import "hqwebapp/spec/bootstrap3/widgets_spec";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import hqMocha from "mocha/js/main";

import "hqwebapp/spec/assert_properties_spec";
import "hqwebapp/spec/email_validator_spec";
import "hqwebapp/spec/bootstrap5/inactivity_spec";
import "hqwebapp/spec/urllib_spec";
import "hqwebapp/spec/bootstrap5/widgets_spec";
Expand Down
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]'));
Copy link
Contributor

Choose a reason for hiding this comment

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

wild

Copy link
Contributor Author

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.

});

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&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',
'me@ex|ample.com',
];
emails.forEach(email => assert.notOk(testEmail(email)));
});
});
});
Loading