Skip to content

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions