zod icon indicating copy to clipboard operation
zod copied to clipboard

Allows email address domains to be IP addresses

Open Tyler-Murphy opened this issue 3 years ago • 6 comments

Sorry I didn't make an issue first. Figured it's a small change, so I'd just offer a solution whether it's acceptable or not.

References:

  • https://learn.microsoft.com/en-us/archive/blogs/testing123/email-address-test-cases
  • https://github.com/validatorjs/validator.js/issues/800

This doesn't make sure the IP address is valid. It only makes sure that it's not obviously invalid.

Tyler-Murphy avatar Sep 27 '22 22:09 Tyler-Murphy

Deploy Preview for guileless-rolypoly-866f8a ready!

Built without sensitive environment variables

Name Link
Latest commit 93be5e57a06ec55c0e8b39bc193d24e008c4e41f
Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/63337cf14aa407000a64eca7
Deploy Preview https://deploy-preview-1435--guileless-rolypoly-866f8a.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

netlify[bot] avatar Sep 27 '22 22:09 netlify[bot]

can you benchmark perf impact of this change on plain emails?

kibertoad avatar Sep 29 '22 21:09 kibertoad

I think validator.js approach of making this optional generally makes more sense, especially if this makes the hot path regex slower

kibertoad avatar Sep 29 '22 22:09 kibertoad

Sure, added to benchmarks/string.ts like this:

const emailSchema = z.string().email()

...

  .add("email", () => {
    emailSchema.parse(`[email protected]`)
  })

Without IP support: 7,224,694 ops/sec ±0.59% (96 runs sampled) With IP support: 7,175,461 ops/sec ±0.62% (92 runs sampled)

I also tried with 1000 random email addresses from https://www.randomlists.com/email-addresses?qty=1000 where each one was checked in a for .. of loop.

Without IP support: 7,459 ops/sec ±0.39% (97 runs sampled) With IP support: 7,584 ops/sec ±0.56% (97 runs sampled)

And finally, I replaced two of the 1000 random email addresses with email addresses that use IP addresses, still using the regex with IP support: 7,663 ops/sec ±0.41% (97 runs sampled)

The speed is so similar that I don't think it's worth making it optional.

Tyler-Murphy avatar Sep 30 '22 02:09 Tyler-Murphy

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[bot] avatar Nov 29 '22 03:11 stale[bot]

Leave open

Tyler-Murphy avatar Nov 29 '22 14:11 Tyler-Murphy

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[bot] avatar May 10 '23 00:05 stale[bot]

Not stale

Tyler-Murphy avatar May 10 '23 18:05 Tyler-Murphy

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[bot] avatar Aug 08 '23 19:08 stale[bot]

not stale

Tyler-Murphy avatar Aug 09 '23 21:08 Tyler-Murphy

Thanks for this (now very old) PR! The final word on email regexes landed here: https://github.com/colinhacks/zod/pull/2157 Further discussion can happen in new issues/PRs. 👍

colinhacks avatar Apr 07 '24 00:04 colinhacks