Skip to content

fix(utils): handle null in isJSONSerializable#579

Open
chu0119 wants to merge 1 commit into
unjs:mainfrom
chu0119:fix/is-json-serializable-null
Open

fix(utils): handle null in isJSONSerializable#579
chu0119 wants to merge 1 commit into
unjs:mainfrom
chu0119:fix/is-json-serializable-null

Conversation

@chu0119
Copy link
Copy Markdown

@chu0119 chu0119 commented May 16, 2026

Summary

Fixed isJSONSerializable(null) throwing TypeError and returning incorrect result.

Root cause

  • typeof null returns "object", so t === null was dead code
  • The null value fell through to value.buffer which threw TypeError: Cannot read properties of null

Fix

Added an explicit value === null check before the typeof check, returning true since null is JSON serializable.

Closes #571

Summary by CodeRabbit

  • Bug Fixes
    • Fixed JSON serialization validation to properly handle null values, preventing errors and ensuring accurate validation of data structures containing null entries.

Review Change Stack

- `null` is JSON serializable but was not recognized as such
- `typeof null` returns `"object"`, making the `t === null` check dead code
- Accessing `value.buffer` on null threw a TypeError
- Fixed by adding an explicit `value === null` check that returns true
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: af4423e1-a1c9-46ba-b297-8d96d421bbb4

📥 Commits

Reviewing files that changed from the base of the PR and between dfbe3ca and 875efc8.

📒 Files selected for processing (1)
  • src/utils.ts

📝 Walkthrough

Walkthrough

isJSONSerializable in src/utils.ts now explicitly handles null values by adding an early value === null check that returns true. This fixes a bug where calling the function with null would throw a TypeError when attempting to access properties on the null value.

Changes

Null handling fix

Layer / File(s) Summary
Null value check
src/utils.ts
isJSONSerializable adds an early value === null branch that returns true, preventing the function from attempting to access properties on null and fixing the TypeError.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A rabbit hops through buggy code,
Where null had caused the greatest load,
Now early checks make all things right,
JSON serialization takes flight! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(utils): handle null in isJSONSerializable' directly describes the main change: fixing null handling in the isJSONSerializable function.
Linked Issues check ✅ Passed The PR addresses all requirements from issue #571: adds explicit null check, returns true for null (JSON serializable), and prevents TypeError when accessing value.buffer.
Out of Scope Changes check ✅ Passed The changes are limited to fixing the null handling bug in isJSONSerializable as specified in issue #571, with no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isJSONSerializable bug

1 participant