Repository navigation
fix(zod): use named argument lookup for @length validation - #2434
Conversation
📝 WalkthroughWalkthroughThis pull request addresses a bug in Zod string validation where Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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 |
|
Claude finished @ymc9's task —— View job Code Review Complete ✅I've thoroughly reviewed this pull request that fixes the @Length validation bug. Here's my comprehensive feedback: Review Checklist:
✅ Overall Assessment: Excellent FixThis is a well-implemented bug fix that correctly addresses the root cause and includes proper testing. Code Quality & Best PracticesCore Fix (packages/zod/src/utils.ts:34-41 & 251-258)✅ Excellent Implementation
Test Coverage (tests/regression/test/issue-2433.test.ts)✅ Comprehensive Testing
Security Considerations✅ No Security Concerns
Performance Considerations✅ Minimal Performance Impact
Potential Issues & SuggestionsMinor: Error HandlingThe code gracefully handles missing arguments with optional chaining ( Code Style ConsistencyThe fix follows the existing code style perfectly. The use of optional chaining and the existing pattern is maintained. Related Files ReviewSQLite Provider Changes (packages/cli/src/actions/pull/provider/sqlite.ts)ℹ️ Unrelated to Main Fix Edge Cases Considered✅ The fix properly handles:
Final Verdict🎯 This is a high-quality bug fix that:
Recommendation: ✅ Approve and merge This fix properly resolves issue #2433 and is ready for production. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/regression/test/issue-2433.test.ts`:
- Around line 6-42: Add a new regression test in issue-2433.test.ts that covers
the combined `@length`(min: N, max: M) constraint: use createTestClient to define
a Post model with content String `@length`(min: 5, max: 10), then assert that
db.post.create succeeds for a string within the range (e.g., length 7) using
resolves.toMatchObject and fails validation for a string shorter than min and
for a string longer than max using toBeRejectedByValidation; place it alongside
the existing it blocks and reuse the same db.post.create assertions pattern.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/cli/src/actions/pull/provider/sqlite.tspackages/zod/src/utils.tstests/regression/test/issue-2433.test.ts
Problem
When using
@lengthwith only amaxargument (e.g.,@length(max: 10)), the validation was incorrectly applying themaxvalue as aminconstraint. This happens because the code used positional indexing (args[0]) to look up the min argument, but whenmaxis specified withoutmin,args[0]holds themaxvalue.Root Cause
In
packages/zod/src/utils.ts, bothaddStringValidationandaddListValidationused positional index[0]and[1]to retrieveminandmaxargs from@lengthattributes, instead of looking them up by name.Fix
Changed the arg lookup to use named lookup (
.find(a => a.name === 'min')and.find(a => a.name === 'max')) for the@lengthattribute in bothaddStringValidationandaddListValidation.Testing
Added regression test
tests/regression/test/issue-2433.test.tsthat verifies:@length(max: N)without min correctly allows short values and rejects values exceeding max@length(min: N, max: M)works correctly with both constraintsFixes #2433
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests