Fix multer latin1 mis-decode for non-ASCII filenames

Mor1arty's fork patches `upload.ts` to re-decode `req.file.originalname` from latin1 to UTF-8, fixing the mangled-filename bug that hits anyone uploading files with Chinese (or any non-ASCII) characters. Ten lines against multer's multipart parsing default.

i18ninfrastructure

Multer inherits Busboy's default behavior of treating the multipart filename header as latin1. For ASCII filenames this is a no-op. For anything outside that range - Chinese, Arabic, Cyrillic, accented Latin - the filename arrives garbled. The fix is the standard recipe: Buffer.from(name, "latin1").toString("utf-8") applied in the singleFileUpload middleware on the success path, before next() is called.

The change is 10 LOC, in one file (backend/src/lib/upload.ts), and only runs when req.file?.originalname is truthy. ASCII users see no behavioral change; the round-trip is a no-op for correctly encoded ASCII bytes.

One caveat: the fix applies unconditionally rather than checking the filename* RFC 5987 parameter first. A client that correctly sends UTF-8 in a filename* field will still get the latin1 re-decode applied - which is safe because the round-trip produces the same string, but a stricter implementation would inspect the encoding directive. For practical purposes in a web upload context this is fine.

The PR was merged from Mor1arty/feature/CN-file-support into main. The merge commit (533a4ed) carries no additional code.

So what Worth a look if your deployment will see uploads from non-Latin locales. The fix is tiny and low-risk to adopt. Skip it if all your users are on ASCII-only filesystems and you have no internationalization requirements.

View this fork on GitHub →

Spotted something wrong? Or know the PR text has fresher detail than the writeup above?

Commits in this thread

2 commits from Mor1arty/mike, oldest first. Source extracted verbatim from the harvested git log.

SHA Subject Author Date
9a3e93bf fix: support uploading file who involves Chinese content Moriarty 2026-05-15 ↗ GitHub
533a4ed9 Merge pull request #1 from Mor1arty/feature/CN-file-support Mor1arty 2026-05-15 ↗ GitHub
fix: support uploading file who involves Chinese content

Capture this thread into my fork

Download a single Markdown prompt that tells Claude how to port every commit above into your working tree — adapting paths and structure to match your repo. Run it via claude -p < capture-thread-439.md from inside the repo you want the changes in.

⬇ Download capture-thread-439.md