feat: valibot validates IP addresses#1555
Conversation
Closes open-circle#342. Add a `cidr(message?)` action that validates both IPv4 CIDR (`192.168.1.0/24`) and IPv6 CIDR (`2001:db8::/32`): the IP part must match IPV4_REGEX or IPV6_REGEX, and the prefix length must be in range (0 32 for IPv4, 0 128 for IPv6). The existing ip/ipv4/ipv6 actions are unchanged.
WalkthroughAdds a CIDR validation action that parses IPv4 and IPv6 address/prefix strings, validates prefix bounds, and reports invalid typed values. It defines typed issue and action interfaces, supports optional custom messages through overloads, and exposes the new action through the CIDR and top-level actions entrypoints. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
library/src/actions/index.ts (1)
37-37: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMaintain alphabetical order for exports.
To maintain consistency with the rest of the barrel file, please move the
cidrexport so that it is positioned alphabetically betweencheckItemsandcreditCard.♻️ Proposed fix
Remove the line from here:
-export * from './cidr/index.ts';And insert it at line 9, so it looks like this:
export * from './checkItems/index.ts'; export * from './cidr/index.ts'; export * from './creditCard/index.ts';🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@library/src/actions/index.ts` at line 37, Move the `cidr` export in the actions barrel file so it appears alphabetically between the `checkItems` and `creditCard` exports, without changing its export statement or other entries.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@library/src/actions/index.ts`:
- Line 37: Move the `cidr` export in the actions barrel file so it appears
alphabetically between the `checkItems` and `creditCard` exports, without
changing its export statement or other entries.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a8ad12e8-7467-49c7-b288-adea43a7fa4e
📒 Files selected for processing (3)
library/src/actions/cidr/cidr.tslibrary/src/actions/cidr/index.tslibrary/src/actions/index.ts
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="library/src/actions/cidr/cidr.ts">
<violation number="1" location="library/src/actions/cidr/cidr.ts:23">
P3: Library formatting CI will reject this new file because it lacks a final newline. End the file with LF so Prettier's check passes.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| const n = Number(prefix); | ||
| if (IPV4_REGEX.test(ip)) { | ||
| return n >= 0 && n <= 32; | ||
| } |
There was a problem hiding this comment.
P3: Library formatting CI will reject this new file because it lacks a final newline. End the file with LF so Prettier's check passes.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At library/src/actions/cidr/cidr.ts, line 23:
<comment>Library formatting CI will reject this new file because it lacks a final newline. End the file with LF so Prettier's check passes.</comment>
<file context>
@@ -0,0 +1,97 @@
+ const n = Number(prefix);
+ if (IPV4_REGEX.test(ip)) {
+ return n >= 0 && n <= 32;
+ }
+ if (IPV6_REGEX.test(ip)) {
+ return n >= 0 && n <= 128;
</file context>
| } | |
| } | |
Closes #342.
Add a
cidr(message?)action that validates both IPv4 CIDR (192.168.1.0/24) and IPv6 CIDR (2001:db8::/32): the IP part must match IPV4_REGEX or IPV6_REGEX, and the prefix length must be in range (0 32 for IPv4, 0 128 for IPv6). The existing ip/ipv4/ipv6 actions are unchanged.Summary by CodeRabbit