Skip to content

Commit

Permalink
fix(email-validation): reject quoted emails with blacklisted characters
Browse files Browse the repository at this point in the history
  • Loading branch information
alokdwivedi103 committed Oct 6, 2024
1 parent 66ddd9c commit 7d7153d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/isEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,14 @@ export default function isEmail(str, options) {
}

if (options.blacklisted_chars) {
// Check for blacklisted characters in the raw user part
if (user.search(new RegExp(`[${options.blacklisted_chars}]+`, 'g')) !== -1) return false;

// If the user part is quoted, remove the quotes and recheck
if (user[0] === '"' && user[user.length - 1] === '"') {
const strippedUser = user.slice(1, user.length - 1);
if (strippedUser.search(new RegExp(`[${options.blacklisted_chars}]+`, 'g')) !== -1) return false;
}
}

if (user[0] === '"' && user[user.length - 1] === '"') {
Expand Down

0 comments on commit 7d7153d

Please sign in to comment.