validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

Email validator accepts special character "¸" which should not be valid

Open RaminGe opened this issue 1 year ago • 7 comments

Describe the bug This email is invalid but the validator returns that it is valid: te¸[email protected]

Examples

// Current behaviour:
console.log(validator.isEmail('te¸[email protected]')); // => true

// Expected behaviour:
console.log(validator.isEmail('te¸[email protected]')); // => false

Additional context Validator.js version: 13.11.0 (latest)

RaminGe avatar Jan 16 '24 10:01 RaminGe

I'm not knowledgeable enough about the exact email standards to determine if this is a bug or not, but you can set the allow_utf8_local_part option to false to mark the email address you provided as invalid. From the README; "If allow_utf8_local_part is set to false, the validator will not allow any non-English UTF8 character in email address' local part"

WikiRik avatar Jan 16 '24 19:01 WikiRik

Thanks @WikiRik I'll use this option. I still think it's an invalid email address in general so I guess it makes sense to show it as invalid in general but maybe it needs some more research to be sure.

RaminGe avatar Jan 17 '24 09:01 RaminGe

I've changed allow_utf8_local_part set to false how do I test it?

devmanbud avatar Jan 29 '24 14:01 devmanbud

I've changed allow_utf8_local_part set to false how do I test it?

Simply pass the email to the function and log it:

// allow_utf8_local_part === false:
console.log(validator.isEmail('te¸[email protected]')); // => true

// allow_utf8_local_part === true:
console.log(validator.isEmail('te¸[email protected]')); // => false

RaminGe avatar Jan 30 '24 08:01 RaminGe

how do I log this

devmanbud avatar Jan 30 '24 10:01 devmanbud

run*

devmanbud avatar Jan 30 '24 10:01 devmanbud

Created pull request for the bug fix: https://github.com/validatorjs/validator.js/pull/2384

Sumit-tech-joshi avatar Mar 29 '24 07:03 Sumit-tech-joshi