Skip to content

Object.prototype.toString.call(form) returns "[object Object]" instead of "[object FormData]" #396

Closed

Description

@ThisIsMissEm

This appears to be due to a change in the algorithm used for determining the toString of an Object. See step 16 of 19.1.3.6 Object.prototype.toString ( )

const form = new FormData();

assert(form.toString() == "[object FormData]", "toString() results in [object FormData]")
assert(Object.prototype.toString.call(form) == "[object FormData]", "Object.prototype.toString.call(form) results in [object FormData]")

In version 2.3.2 of FormData, the second assertion will fail as Object.prototype.toString.call(form) returns [object Object]

The fix for this is to add support for the toStringTag symbol, like the following:

if (Symbol && Symbol.toStringTag) {
  Object.defineProperty(FormData.prototype, Symbol.toStringTag, {
    value: 'FormData',
    writable: false,
    enumerable: false,
    configurable: true
  });
}

Activity

  1. henryozoebuka commented on Feb 12, 2025

    @henryozoebuka
  2. ljharb commented on Feb 12, 2025

    @ljharb
  3. ThisIsMissEm commented on Feb 12, 2025

    @ThisIsMissEm
    Author
  4. henryozoebuka commented on Feb 13, 2025

    @henryozoebuka
  5. ljharb commented on Feb 13, 2025

    @ljharb
  6. added 2 commits that reference this issue on Feb 14, 2025
    999d76a
    e997b90
  7. added 2 commits that reference this issue on Feb 14, 2025
    f80033f
    84ca1d6
  8. ljharb commented on Feb 14, 2025

    @ljharb
    Member

    Released in v4.0.2 and backported to v3.0.3 and v2.5.3.

  9. engPabloMartinez commented on Nov 17, 2025

    @engPabloMartinez

    I can still see this same behaviour on 4.04

  10. ljharb commented on Nov 17, 2025

    @ljharb
    Member

    @engPabloMartinez on which engine?

    setToStringTag(FormData, 'FormData');
    sets the Symbol.toStringTag value.

  11. engPabloMartinez commented on Nov 17, 2025

    @engPabloMartinez

    I am seeing this in a NextJS application on the server side, so NodeJS.

    const formData = new FormData();
    formData.append('file', fs.createReadStream(/tmp/${fileName}));
    formData.append(
    'type',
    mimeType === 'image/jpg' ? 'image/jpeg' : mimeType
    );
    console.log('Prototype: ', Object.prototype.toString.call(formData));
    console.log('toString: ', formData.toString());

    And I get

    Prototype: [object Object]
    toString: [object FormData]

  12. ljharb commented on Nov 17, 2025

    @ljharb
    Member

    Thanks, I've reproduced it and will have a fix out shortly.

  13. ljharb commented on Nov 17, 2025

    @ljharb
    Member

    v4.0.5 is released.

  14. engPabloMartinez commented on Nov 17, 2025

    @engPabloMartinez

    Thanks, now it is working.

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