Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
FuJa0815 opened this issue Oct 22, 2024 · 1 comment · Fixed by #3768
Closed

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

FuJa0815 opened this issue Oct 22, 2024 · 1 comment · Fixed by #3768
Labels
bug Something isn't working

Comments

@FuJa0815
Copy link

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

@FuJa0815 FuJa0815 added the bug Something isn't working label Oct 22, 2024
@KhafraDev
Copy link
Member

KhafraDev commented Oct 22, 2024

I will take a look in a few days. We switched formdata parsers, probably ended up between those two versions of node, and I guess I forgot to implement filename* parsing support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants