fix: treat null as JSON-serializable in isJSONSerializable#607
Conversation
typeof null is "object", so the t === null branch was dead code (t is always a string). isJSONSerializable(null) fell through to value.buffer and threw "Cannot read properties of null". null is JSON-serializable, so check value === null and return true instead. Resolves unjs#571
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughFixed a bug in ChangesisJSONSerializable null fix
Estimated code review effort: 1 (Trivial) | ~5 minutes Related issues: Fixes Suggested labels: bug, tests Suggested reviewers: pi0 🚥 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 |
Since
typeof nullis"object", thet === nullbranch inisJSONSerializablewas dead code (tis always a string). As a resultisJSONSerializable(null)fell through to thevalue.bufferaccess and threwTypeError: Cannot read properties of null (reading 'buffer').nullis JSON-serializable (JSON.stringify(null) === "null"), so this checksvalue === nullup front and returnstrue, which also removes the dead check.No behavior change for
$fetchitself — anullbody is already short-circuited by thecontext.options.body &&guard before this util is reached; the fix matters for direct/library use of the exported helper.Resolves #571
Summary by CodeRabbit
Bug Fixes
nullvalues so they are now correctly recognized as JSON-serializable.undefined, functions, and typed arrays.Tests