zod
zod copied to clipboard
Allows email address domains to be IP addresses
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.
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...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site settings.
can you benchmark perf impact of this change on plain emails?
I think validator.js approach of making this optional generally makes more sense, especially if this makes the hot path regex slower
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.
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.
Leave open
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.
Not stale
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.
not stale
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. 👍