zod
zod copied to clipboard
z.string().email() allows invalid emails with a comma
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,[email protected]',
};
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
its a near impossible task to make this cover all cases. for instance this:
"@dk" is a valid email
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 :)
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 ;)
Fixed in Zod 3.23.0
Fixed in Zod 3.23.0
I believe this should've been closed