Skip to content

Commit 3448e9d

Browse files
fix(isEmail): blacklist character check fix for #2392 (#2414)
1 parent 08257b5 commit 3448e9d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/lib/isEmail.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ export default function isEmail(str, options) {
162162
}
163163
}
164164

165+
if (options.blacklisted_chars) {
166+
if (user.search(new RegExp(`[${options.blacklisted_chars}]+`, 'g')) !== -1) return false;
167+
}
168+
165169
if (user[0] === '"') {
166170
user = user.slice(1, user.length - 1);
167171
return options.allow_utf8_local_part ?
@@ -178,9 +182,6 @@ export default function isEmail(str, options) {
178182
return false;
179183
}
180184
}
181-
if (options.blacklisted_chars) {
182-
if (user.search(new RegExp(`[${options.blacklisted_chars}]+`, 'g')) !== -1) return false;
183-
}
184185

185186
return true;
186187
}

test/validators.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,15 @@ describe('Validators', () => {
265265
it('should not validate email addresses with blacklisted chars in the name', () => {
266266
test({
267267
validator: 'isEmail',
268-
args: [{ blacklisted_chars: 'abc' }],
268+
args: [{ blacklisted_chars: 'abc"' }],
269269
valid: [
270270
'emil@gmail.com',
271271
],
272272
invalid: [
273273
'email@gmail.com',
274+
'"foobr"@example.com',
275+
'" foo m端ller "@example.com',
276+
'"foo\@br"@example.com',
274277
],
275278
});
276279
});

0 commit comments

Comments
 (0)