Skip to content

Commit 69975c3

Browse files
authored
Merge pull request #890 from Expensify/beaman-fixMapDomainIssue
Handle no email in `isValidEmail` check
2 parents 4b8a4bb + c9f1acd commit 69975c3

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

__tests__/Str-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ describe('Str.isValidEmail', () => {
192192
// TLD too long
193193
expect(Str.isValidEmail('a@a.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl')).toBeFalsy();
194194
});
195+
196+
it('Handles undefined and null values gracefully', () => {
197+
expect(Str.isValidEmail(undefined)).toBeFalsy();
198+
expect(Str.isValidEmail(null)).toBeFalsy();
199+
expect(Str.isValidEmail('')).toBeFalsy();
200+
});
195201
});
196202

197203
describe('Str.isValidPhoneFormat', () => {

lib/str.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@ const Str = {
406406
* @returns True if the string is an email
407407
*/
408408
isValidEmail(str: string): boolean {
409+
if (!str || typeof str !== 'string') {
410+
return false;
411+
}
409412
const unicodeVersion = Punycode.toUnicode(str);
410413
if (String(unicodeVersion).match(Constants.CONST.REG_EXP.EMOJI_RULE)) {
411414
return false;

0 commit comments

Comments
 (0)