Skip to content

"Failed to parse body as FormData." with filename*=utf-8 content disposition #3760

@FuJa0815

Description

@FuJa0815

Bug Description

When sending a multipart/form-data with a filename*=utf-8'' (as the MultipartFormDataContent class in C# does for example, or in this example in the RFC: https://datatracker.ietf.org/doc/html/rfc6266#section-5) content disposition it throws a "Failed to parse body as FormData." TypeError.

Reproducible By

const response = new Response([
    '--83d82e0d-9ced-44c0-ac79-4e66a827415b\r\n' +
    'Content-Type: text/plain\r\n' +
    'Content-Disposition: form-data; name="file"; filename*=utf-8\'\'file%20name.txt\r\n' +
    '\r\n' +
    'testabc\r\n' +
    '--83d82e0d-9ced-44c0-ac79-4e66a827415b--\r\n' +
    '\r\n',
  ].join(''), {
    headers: {
      'content-type': 'multipart/form-data; boundary="83d82e0d-9ced-44c0-ac79-4e66a827415b"'
    }
  });

await response.formData()

Expected Behavior

The existance of a filename*=utf-8 field shouldn't lead to parse failure, it should be used as the filename.

Logs & Screenshots

node:internal/deps/undici/undici:5619
                    throw new TypeError("Failed to parse body as FormData.");
                          ^

TypeError: Failed to parse body as FormData.
    at node:internal/deps/undici/undici:5619:27
    at successSteps (node:internal/deps/undici/undici:5663:27)
    at fullyReadBody (node:internal/deps/undici/undici:4561:9)
    at async consumeBody (node:internal/deps/undici/undici:5672:7)
    at async file:///index.js:15:1

Environment

This bug is NOT present in node v20.12.2, but IS present from node v20.13 and onward.

Additional context

Workaround: downgrade to node v20.12.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions