Skip to content

feat: valibot validates IP addresses#1555

Open
hazrid93 wants to merge 1 commit into
open-circle:mainfrom
hazrid93:hazrid93/28_342
Open

feat: valibot validates IP addresses#1555
hazrid93 wants to merge 1 commit into
open-circle:mainfrom
hazrid93:hazrid93/28_342

Conversation

@hazrid93

@hazrid93 hazrid93 commented Jul 20, 2026

Copy link
Copy Markdown

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

  • New Features
    • Added CIDR validation for IPv4 and IPv6 addresses with supported prefix-length checks.
    • Added customizable validation messages for CIDR errors.
    • Exposed the CIDR validator through the library’s public actions API.

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.
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Adds 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)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is related, but it is broader than the change because the PR adds CIDR validation rather than general IP validation.
Linked Issues check ✅ Passed The PR adds a dedicated cidr action that validates IPv4/IPv6 CIDR notation, matching the requested CIDR schema type.
Out of Scope Changes check ✅ Passed The changes stay focused on adding CIDR validation and public re-exports, with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
library/src/actions/index.ts (1)

37-37: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Maintain alphabetical order for exports.

To maintain consistency with the rest of the barrel file, please move the cidr export so that it is positioned alphabetically between checkItems and creditCard.

♻️ 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

📥 Commits

Reviewing files that changed from the base of the PR and between 90bc2c7 and 660fff8.

📒 Files selected for processing (3)
  • library/src/actions/cidr/cidr.ts
  • library/src/actions/cidr/index.ts
  • library/src/actions/index.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Suggested change
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add CIDR Schema Type

1 participant