fix: treat null as JSON-serializable (isJSONSerializable(null) throws) - #625
fix: treat null as JSON-serializable (isJSONSerializable(null) throws)#625DanMat wants to merge 1 commit into
Conversation
isJSONSerializable(null) threw "Cannot read properties of null (reading 'buffer')": `t === null` was dead code (typeof returns a string, never null), so null fell through to `value.buffer`. null is valid JSON, so it should return true. Replace the dead check with `value === null`. Adds a unit test for the util (previously untested). Closes unjs#571
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan includes up to 8 reviews per rolling hour; 7 remain after this review. 📝 WalkthroughWalkthrough
ChangesJSON serialization validation
Estimated code review effort: 1 (Trivial) | ~5 minutes Merge Risk: ⚪ Minimal · up to This change makes null correctly report as JSON-serializable and adds focused coverage for the utility; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
Closes #571.
isJSONSerializable(null)currently throwsCannot read properties of null (reading 'buffer'):t === nullis dead code —typeofalways returns a string, nevernull.nullisn't caught there, falls past thet !== "object"guard, and reachesvalue.buffer, which throws.nullis valid JSON (JSON.stringify(null) === "null"), so it should returntrue. This replaces the deadt === nullcheck withvalue === null, catchingnullbefore the.bufferaccess.Also adds
test/utils.test.ts— the util had no direct unit test — coveringnull, primitives, plain objects/arrays, andFormData/URLSearchParams. All existing tests still pass; lint clean.Disclosure: this change was written with AI assistance. I've reviewed, tested, and understand it, and I'll maintain it.
Summary by CodeRabbit
Bug Fixes
nullis recognized as a supported value without causing errors.Tests