unjs / unjs/ofetch

Bug: isJSONSerializable returns false for empty FormData and URLSearchParams

Open Beginner friendly
#580 0 comments 0 reactions 0 assignees View on GitHub

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

  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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.