Skip to content

Commit

Permalink
fix: verify that email address has a maximum length of 254 characters (
Browse files Browse the repository at this point in the history
  • Loading branch information
danruehle authored and eventualbuddha committed Oct 24, 2017
1 parent 45de1ee commit 73a47fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lgtm/helpers/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const STRICT_CHARS = /^[\x20-\x7F]*$/;
// http://stackoverflow.com/a/46181/11236
const EMAIL = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

// http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690
const MAX_EMAIL_LENGTH = 254;

export function checkEmail(options = {}) {
return function(value) {
if (typeof value === 'string') {
Expand All @@ -24,7 +27,12 @@ export function checkEmail(options = {}) {
}
}

return EMAIL.test(value);
return (
value !== undefined &&
value !== null &&
value.length <= MAX_EMAIL_LENGTH &&
EMAIL.test(value)
);
};
}

Expand Down
12 changes: 12 additions & 0 deletions test/helpers/core_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ describe('helpers.core', () => {
!checkEmail({ strictCharacters: true })('mañana@squareup.com'),
'returns false for emails with characters in extended ASCII range when strictCharacters == true'
);
ok(
checkEmail()('github' + '+'.repeat(235) + '@squareup.com'),
'returns true for email with length of 254 characters'
);
ok(
checkEmail()('github' + '+'.repeat(235) + '@squareup.com'),
'returns true for email with length of 254 characters'
);
ok(
!checkEmail()('github' + '+'.repeat(236) + '@squareup.com'),
'returns false for email with length greater than 254 characters'
);
});

it('checkMinLength', () => {
Expand Down

0 comments on commit 73a47fc

Please sign in to comment.