fix: handle null and FormData order in isJSONSerializable#589
Conversation
|
Warning Review limit reached
More reviews will be available in 6 minutes and 24 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughisJSONSerializable now returns true for null via an explicit early-return and rejects FormData/URLSearchParams before accessing value.buffer. A Vitest suite was added to assert false for FormData/URLSearchParams (empty and with entries) and true for null. ChangesType Check Reordering and Test Coverage
🎯 2 (Simple) | ⏱️ ~10 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/index.test.ts (1)
537-544: ⚡ Quick winAdd a populated
URLSearchParamsassertion for symmetry.This suite checks populated
FormDatabut not populatedURLSearchParams; adding one assertion strengthens regression coverage for the same branch behavior.Proposed test addition
it("returns false for FormData and URLSearchParams before buffer checks", () => { expect(isJSONSerializable(new FormData())).toBe(false); expect(isJSONSerializable(new URLSearchParams())).toBe(false); + expect(isJSONSerializable(new URLSearchParams({ foo: "bar" }))).toBe(false); const data = new FormData(); data.append("foo", "bar"); expect(isJSONSerializable(data)).toBe(false); });🤖 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 `@test/index.test.ts` around lines 537 - 544, Add a populated URLSearchParams assertion symmetric to the existing FormData check: in the test block that calls isJSONSerializable for FormData and URLSearchParams, construct a URLSearchParams instance, append a key/value (e.g., "foo", "bar"), and assert isJSONSerializable(populatedUrlSearchParams) === false so the test covers the populated-URLSearchParams branch alongside the populated-FormData check; locate this in test/index.test.ts within the "returns false for FormData and URLSearchParams before buffer checks" test that references isJSONSerializable.
🤖 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 `@test/index.test.ts`:
- Around line 537-544: Add a populated URLSearchParams assertion symmetric to
the existing FormData check: in the test block that calls isJSONSerializable for
FormData and URLSearchParams, construct a URLSearchParams instance, append a
key/value (e.g., "foo", "bar"), and assert
isJSONSerializable(populatedUrlSearchParams) === false so the test covers the
populated-URLSearchParams branch alongside the populated-FormData check; locate
this in test/index.test.ts within the "returns false for FormData and
URLSearchParams before buffer checks" test that references isJSONSerializable.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0f015ae0-802e-43fc-b28f-9808217af2bd
📒 Files selected for processing (2)
src/utils.tstest/index.test.ts
Summary
truefornullvia explicit check (typeof nullis"object")FormData/URLSearchParamsbeforevalue.bufferto avoid throws on empty instancesExample
Fixes #571
Fixes #580
Test plan
pnpm testpassesnulland FormDataSummary by CodeRabbit
Bug Fixes
Tests