isJSONSerializable bug
Nobody has claimed this yet.
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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