Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normalizeEmail can break with quoted "@" in user part #594

Closed
geoffreak opened this issue Oct 14, 2016 · 1 comment
Closed

normalizeEmail can break with quoted "@" in user part #594

geoffreak opened this issue Oct 14, 2016 · 1 comment

Comments

@geoffreak
Copy link

When running normalizeEmail on email addresses that contain a quoted @ in the user part (which is legal and correctly identified by isEmail), it will return an invalid email address.

const validator = require('validator');

let email = '"test@example"@example.com';
console.log(validator.isEmail(email)); // true

let normalized = validator.normalizeEmail(email);
console.log(normalized); // "test@example"
console.log(validator.isEmail(normalized)); // false

Expected output for the last two lines:

console.log(normalized); // "test@example"@example.com
console.log(validator.isEmail(normalized)); // true

I would advise splitting the email in this fashion instead of assuming that a .split('@') would return an array of length 2:

let domainSplit = email.split('@');
let domain = domainSplit[domainSplit.length - 1];
let user = domainSplit.slice(0, domainSplit.length - 1).join('@');
@chriso
Copy link
Collaborator

chriso commented Oct 15, 2016

Thanks for reporting.

@chriso chriso closed this as completed in b1b6c1e Oct 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants