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

False positive for .email() validation with sub-domain present? #2154

Closed
JK-WP opened this issue Mar 7, 2023 · 4 comments
Closed

False positive for .email() validation with sub-domain present? #2154

JK-WP opened this issue Mar 7, 2023 · 4 comments
Labels
bug-confirmed Bug report that is confirmed stale No activity in last 60 days

Comments

@JK-WP
Copy link

JK-WP commented Mar 7, 2023

I've come across what I believe to be some false positives with the string .email() validation, where it doesn't appear to like subdomains. Here is a simple repro:

import { z } from 'zod';

const data = [
  '[email protected]',
  '[email protected]',
  '[email protected]',
  '[email protected]',
];

for (const email of data) {
  console.log(z.string().email().safeParse(email));
}

which produces:

{ success: true, data: '[email protected]' }
{ success: false, error: [Getter] }
{ success: true, data: '[email protected]' }
{ success: false, error: [Getter] }

This is flagging up validation errors in my project for real email addresses resembling the 4th entry in the above repro.
I can see from the code that this behavior is driven by a rather formidable looking regexp; please could you clarify - is a validation failure on an address such as [email protected] intentional? Thanks!

@colinhacks
Copy link
Owner

Nope, not intentional. Thanks for reporting. It's hard to find a regex that pleases everyone, but this is a pretty glaring flaw.

@JacobWeisenburger JacobWeisenburger added the bug-confirmed Bug report that is confirmed label Mar 7, 2023
@fullstackzach
Copy link

Here's another valid example I noticed today, that can be common in the US.
[email protected]

@slightlybelowzen
Copy link

Is anyone else working on this, if not I'd be happy to pick it up!

@stale
Copy link

stale bot commented Jun 23, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale No activity in last 60 days label Jun 23, 2023
@stale stale bot closed this as completed Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-confirmed Bug report that is confirmed stale No activity in last 60 days
Projects
None yet
Development

No branches or pull requests

5 participants