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

Safari Unsupported Email Regex #1668

Closed
CameronB15 opened this issue Dec 12, 2022 · 4 comments · Fixed by #1683
Closed

Safari Unsupported Email Regex #1668

CameronB15 opened this issue Dec 12, 2022 · 4 comments · Fixed by #1683

Comments

@CameronB15
Copy link

The email regex defined here https://github.com/colinhacks/zod/blob/master/src/types.ts#L518 is not supported on Safari.

// old version: too slow, didn't support unicode
// const emailRegex = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
// eslint-disable-next-line
const emailRegex =
  /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@((?!-)([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})(?<!-)$/i;

This is the problematic capture group: (?<!-). This is a negative lookbehind, which isn't supported on Safari https://caniuse.com/js-regexp-lookbehind. Sorry, I'm not sure what it should be re-written to, but I find that https://regexr.com/ is fantastic for testing regular expressions (and highlights the issue with the negative lookbehind too).

@auskast
Copy link

auskast commented Dec 12, 2022

There is a WebKit PR open to implement lookbehind as well.

@colinhacks
Copy link
Owner

I'm open to switching a regex without a negative look-behind. Open to proposals here.

@simPod
Copy link
Contributor

simPod commented Dec 12, 2022

But we should revert #1648 until there's a solution found since it silently breaks apps for safari users.

@colinhacks
Copy link
Owner

Just reverted, landing in 3.20.2 momentarily

AnatoleLucet added a commit to AnatoleLucet/zod that referenced this issue Dec 12, 2022
AnatoleLucet added a commit to AnatoleLucet/zod that referenced this issue Dec 12, 2022
AnatoleLucet added a commit to AnatoleLucet/zod that referenced this issue Dec 13, 2022
iduuck added a commit to iduuck/groqd that referenced this issue Dec 14, 2022
gksander added a commit to FormidableLabs/groqd that referenced this issue Dec 14, 2022
* update zod to 3.20.2 (fixes #8)

see more colinhacks/zod#1668 (comment)

* Update yarn.lock

Co-authored-by: Grant Sander <gksander93@gmail.com>
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

Successfully merging a pull request may close this issue.

4 participants