unjs / unjs/ofetch

isJSONSerializable bug

Open
#571 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
5.4k
Forks
195
PR merge metrics
No merged PRs in 30d

Description

Environment

Any environment, any version. Present from the start it seems like.

Reproduction

Running isJSONSerializable(null) serves sufficiently as a reproduction of the bug.

Describe the bug

This line has a bug.
https://github.com/unjs/ofetch/blob/dfbe3ca4ef8a22fc023fca5a5ef530e525f5e523/src/utils.ts#L22

Firstly, t (typeof value) will never triple equal null. (dead code)
Secondly, null as a value is JSON serializable. This util function will not identify it as such.
Thirdly, if you provide null to this util function, it will throw:

Uncaught TypeError: Cannot read properties of null (reading 'buffer')
    at isJSONSerializable
Additional context

Can I create a PR fix?

Logs

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at src/utils.ts line 22 and run the reported reproduction, isJSONSerializable(null). Check the utility's handling of null and verify that the completed change treats null as JSON-serializable without throwing, while preserving the existing behavior for other values.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.