Skip to content

Bug: isJSONSerializable returns false for empty FormData and URLSearchParams #580

@chu0119

Description

@chu0119

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions