fix: isJSONSerializable returns true for null (#571)#596
Conversation
Fixes unjs#571 The bug was on line 22 where it checked `t === null`, but typeof never returns "null" (typeof null === "object"). This caused: 1. Dead code: t === null was always false 2. isJSONSerializable(null) threw TypeError accessing null.buffer 3. null was incorrectly identified as not JSON serializable Fixed by: - Adding explicit null check before typeof comparison - Removing t === null from typeof checks (impossible condition) Tests: - Added comprehensive unit tests for isJSONSerializable - All tests pass including null, undefined, primitives, and edge cases
|
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)
📝 WalkthroughWalkthroughFixes a bug in ChangesisJSONSerializable null fix and tests
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 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 |
Fixes #571
Bug Description:
The function had a critical bug on line 22 where it checked
t === null,but
typeofnever returns "null" (typeof null === "object").This caused three issues:
t === nullwas always falseisJSONSerializable(null)threw TypeError: "Cannot read properties of null (reading buffer)"Changes:
value === nullcheck before typeof comparisont === nullfrom typeof checks (impossible condition)Testing:
Summary by CodeRabbit
Bug Fixes
Tests