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

z.string().email() allows invalid emails with a comma #3389

Open
anthony-healthstreet opened this issue Apr 8, 2024 · 4 comments
Open

z.string().email() allows invalid emails with a comma #3389

anthony-healthstreet opened this issue Apr 8, 2024 · 4 comments

Comments

@anthony-healthstreet
Copy link

It seems that the zod validation for email is allowing commas through which does not match the RFC 5322 standards.

I'm on version 3.22.4

To reproduce (playground link):

import { z } from 'zod';

const myschmea = z.object({
  email: z.string().email(),
});

const test = {
  email: 'test,dumb@company.com',
};

const parse = myschmea.safeParse(test);

console.log(parse);

const appDiv: HTMLElement = document.getElementById('app');
appDiv.innerHTML =
  `<h1>TypeScript Zod Playground<br>` + JSON.stringify(parse) + `</h1>`;

Workaround - Disable typing of commas into input fields

@klh
Copy link

klh commented Apr 11, 2024

its a near impossible task to make this cover all cases.
for instance this:

"@dk" is a valid email

@dk
Copy link

dk commented Apr 11, 2024

None of my business, but since you mentioned me here (as @dk), there is a brilliant book by jeffrey friedl about regexes, where he covers exactly rfc-strict email parsing :)

@klh
Copy link

klh commented Apr 11, 2024

None of my business, but since you mentioned me here (as @dk), there is a brilliant book by jeffrey friedl about regexes, where he covers exactly rfc-strict email parsing :)

hahah I get that all the time with @threads and @klh ;)

@colinhacks
Copy link
Owner

Fixed in Zod 3.23.0

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

4 participants