File tree Expand file tree Collapse file tree 2 files changed +9
-0
lines changed
Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Original file line number Diff line number Diff 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
197203describe ( 'Str.isValidPhoneFormat' , ( ) => {
Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments