-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(#2758): z.string().ipRange() - add support for IP address range #3754
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for guileless-rolypoly-866f8a ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
This looks really good, I was just in need for this exact functionality. |
I have nothing productive to contribute other than this would be really nice to have land in a release! |
Notice: Updated to follow the latest main branch. |
function isValidCidr(ip: string, version?: IpVersion) { | ||
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) { | ||
return true; | ||
} | ||
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[FYI] Just moved isValidCidr
slightly up.
} else if (check.kind === "ipRange") { | ||
if (!isValidIPRange(input.data, check.cidr, check.version)) { | ||
ctx = this._getOrReturnCtx(input, ctx); | ||
addIssueToContext(ctx, { | ||
validation: "jwt", | ||
validation: "ipRange", | ||
code: ZodIssueCode.invalid_string, | ||
message: check.message, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[FYI] I just rearranged the order so that all ip-related code is grouped together for better readability.
The internal code hasn't been changed 👍
This pull request fixes #2758 adding IP Address range (CIDR) validation in zod string.
relate: #3820