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

parsing formdata headers incorrectly. #20793

Closed
jimmywarting opened this issue Oct 4, 2023 · 1 comment · Fixed by #20801
Closed

parsing formdata headers incorrectly. #20793

jimmywarting opened this issue Oct 4, 2023 · 1 comment · Fixed by #20801

Comments

@jimmywarting
Copy link
Contributor

jimmywarting commented Oct 4, 2023

var type = `multipart/form-data;boundary=----formdata-polyfill-0.970665446687947`
var body = "------formdata-polyfill-0.970665446687947\r\nContent-Disposition: form-data; name=\"x\"; filename=\"blob\"\r\nContent-Length: 1\r\nContent-Type: application/octet-stream\r\nlast-modified: Wed, 04 Oct 2023 20:28:45 GMT\r\n\r\ny\r\n------formdata-polyfill-0.970665446687947--"

new Response(body, {
  headers: {
    'content-type': type
  }
}).formData().then(async fd => {
  const file = fd.get('x')
  const text = await file.text()
  console.assert(text === 'y', `expected "${text}" to equal "y"`)
  console.assert(file.size === 1, `expected file size to be 1, got ${file.size}`)
  console.log('done')
})

This works OK in firefox, safari, chromium, NodeJS, bun, but not in deno...

This is my log:

$ deno run main.js
Assertion failed: expected "last-modified: Wed, 04 Oct 2023 20:28:45 GMT

y" to equal "y"
Assertion failed: expected file size to be 1, got 49
done

it appars as if you are parsing the headers incorrectly...
a multipart/form-data can have a bunch of headers (each separated by \r\n) up on encountering a empty line \r\n should you start reading the content as the body.

@marcosc90
Copy link
Contributor

I'll take a look.

@jimmywarting jimmywarting changed the title parsing formdata incorrectly. parsing formdata headers incorrectly. Oct 5, 2023
marcosc90 added a commit to marcosc90/deno that referenced this issue Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants