helapkg / hela

:icecream: Powerful software development experience and management. Enhancing @tc39 JS, @denoland and @nodejs, because we need a bit of magic. :sparkles: You can think of it as Cargo for the JavaScript ecosystem.
Mozilla Public License 2.0
331 stars 41 forks source link

koa-better-body doesn't correctly parse ampersands in multipart form #80

Closed manuscriptmastr closed 7 years ago

manuscriptmastr commented 7 years ago

I'm using koa-better-body as middleware for a backend-only web application. When I submit a multipart form with a text description that has an ampersand (i.e. "Love this B&W shot"), the browser correctly sends the payload, but better-body turns the part after the ampersand into a new field. Think the error is happening here:

https://github.com/tunnckoCore/koa-better-body/blob/master/utils.js#L208-L214

Does it look that's where the problem is? I'd be happy to submit a pull request if someone isn't already addressing this.

Example:

Chrome sends server:

------WebKitFormBoundaryJyFdnMnS1k2XUhGH
Content-Disposition: form-data; name="image"; filename="IMG_2194.jpg"
Content-Type: image/jpeg

------WebKitFormBoundaryJyFdnMnS1k2XUhGH
Content-Disposition: form-data; name="description"

I love me some &sandisgood
------WebKitFormBoundaryJyFdnMnS1k2XUhGH
Content-Disposition: form-data; name="type"

Cortado

ctx.request.fields prints out:

{ description: 'I love me some ',
  sandisgood: '',
  type: 'Cortado',
  image: 
   [ File {...} ] }
tunnckoCore commented 7 years ago

Mmm.. not sure, but yea, probably. I thought for some fix about these lines.