Bug: isJSONSerializable returns false for empty FormData and URLSearchParams
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.4k
- Forks
- 195
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
isJSONSerializable correctly excludes FormData and URLSearchParams instances (which aren't JSON serializable). However, it also returns false for EMPTY FormData and URLSearchParams instances, which could arguably be treated as serializable (they'd serialize to {}).
More critically, the check value.buffer on line 31 can throw for certain edge cases before reaching the instanceof checks.
Suggested improvement
Move the instanceof checks before the value.buffer check to ensure safer type discrimination.
Environment
- ofetch: all versions
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 with isJSONSerializable and inspect the value.buffer check around line 31, along with the FormData and URLSearchParams handling described in the issue. Verify the type checks safely handle the reported edge cases and that empty instances receive the intended result; done means the regression is covered by the project's relevant tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100