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

IPv6 validation error #3512

Closed
avegao opened this issue May 22, 2024 · 1 comment · Fixed by #3513
Closed

IPv6 validation error #3512

avegao opened this issue May 22, 2024 · 1 comment · Fixed by #3513

Comments

@avegao
Copy link
Contributor

avegao commented May 22, 2024

IPv6 validation fails when the last two parts of the IPv6 are compressed, both when one or both are omitted. It does not happen if it is any other part. I have checked the regex you use in

/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
and I have also checked it in external tools and the zod behavior is reproduced.

const ip = '2001:4888:50:ff00:500:d::';
const schema = z.string().ip();
const { success } = schema.safeParse(ip); // false
const ip = '2001:4888:50:ff00:500:d:0:0';
const schema = z.string().ip();
const { success } = schema.safeParse(ip); // true
const ip = '2001:4888:50:ff00::d:0:0';
const schema = z.string().ip();
const { success } = schema.safeParse(ip); // true
@ffraenz
Copy link

ffraenz commented May 29, 2024

I can confirm this issue. In my logs I found that z.string().ip().safeParse('2a00:116a:105:2e70::') results in "Invalid ip", although being perfectly fine. Thank you for reporting it and proposing a fix!

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.

2 participants