fix: check null before typeof in isJSONSerializable#578
Conversation
typeof null returns 'object', not null, so t === null is always false (dead code). When value is null, it falls through to the object branch and crashes on value.buffer access. Move null check to use value === null before typeof comparison. Fixes #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 (1)
📝 WalkthroughWalkthroughThe ChangesNull value JSON serialization
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 |
Problem
isJSONSerializable(null)throws:Root Cause
typeof nullreturns"object", notnull. Sot === null(wheret = typeof value) is alwaysfalse— it is dead code. Whenvalueisnull, it falls through to the object branch and crashes onvalue.bufferaccess.Fix
Move the null check to use
value === nullbefore the typeof comparison:Fixes #571
Summary by CodeRabbit
Bug Fixes