Skip to content

Commit

Permalink
Fix(bug): Fixes Issue validatorjs#2392
Browse files Browse the repository at this point in the history
  • Loading branch information
keshavlingala committed Jun 4, 2024
1 parent 316188d commit fb74fd0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/lib/isEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ export default function isEmail(str, options) {
}
}

if (options.blacklisted_chars) {
if (user.search(new RegExp(`[${options.blacklisted_chars}]+`, 'g')) !== -1) return false;
}

if (user[0] === '"') {
user = user.slice(1, user.length - 1);
return options.allow_utf8_local_part ?
Expand All @@ -178,9 +182,6 @@ export default function isEmail(str, options) {
return false;
}
}
if (options.blacklisted_chars) {
if (user.search(new RegExp(`[${options.blacklisted_chars}]+`, 'g')) !== -1) return false;
}

return true;
}
5 changes: 4 additions & 1 deletion test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,15 @@ describe('Validators', () => {
it('should not validate email addresses with blacklisted chars in the name', () => {
test({
validator: 'isEmail',
args: [{ blacklisted_chars: 'abc' }],
args: [{ blacklisted_chars: 'abc"' }],
valid: [
'emil@gmail.com',
],
invalid: [
'email@gmail.com',
'"foobr"@example.com',
'" foo m端ller "@example.com',
'"foo\@br"@example.com',
],
});
});
Expand Down

0 comments on commit fb74fd0

Please sign in to comment.