mscdex / busboy

A streaming parser for HTML form data for node.js
MIT License
2.84k stars 213 forks source link

filename with non-ASCII characters is corrupted during upload #316

Closed dschmitt2 closed 2 years ago

dschmitt2 commented 2 years ago

Using busboy 1.6.0 and Firefox. (Same behavior with busboy 1.5.0 or Ungoogled Chromium)

When trying to upload a file with special Unicode characters in the name, an additional character gets injected.

For example, when uploading X©onstants.ts with the following handler:

bb.on("file", (fieldname, stream, info) => {
  console.log(`Incoming name: ==${info.filename}==`);
}

This is what I see:

Incoming name: ==X©onstants.ts==

From the Developer Tools I see that the original name was sent from the browser:

-----------------------------29727020558344325852980456311
Content-Disposition: form-data; name="file_content"; filename="X©onstants.ts"
Content-Type: text/vnd.trolltech.linguist

...
mscdex commented 2 years ago

Set defParamCharset to whatever charset you want to use to decode parameter values that don't have a version of the field with an explicit/inline charset defined. By default it decodes to a latin1 string.