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

Fix UTF-8 file name encoding for uploads (fixes #3013) #3058

Merged
merged 1 commit into from
Aug 14, 2022

Conversation

eliandoran
Copy link
Sponsor Collaborator

@eliandoran eliandoran commented Aug 14, 2022

Attempting to upload a note containing UTF-8 characters will result in a wrong interpretation of the name. It can easily be tested by creating a file called Helău world.txt and trying to upload it.

Not a client problem, since the payload looks fine:

-----------------------------35722791636796930272418934920
Content-Disposition: form-data; name="upload"; filename="Helău.txt"
Content-Type: text/plain

 Helău world

The parsing gets worse in the server:

{
  fieldname: 'upload',
  originalname: 'HelÄ\x83u.txt',
  encoding: '7bit',
  mimetype: 'text/plain',
  buffer: <Buffer 20 48 65 6c c4 83 75 20 77 6f 72 6c 64 0a>,
  size: 14
}

Seems like there's an entire story regarding why UTF-8 characters are not well parsed:

The change on the server side is rather trivial: enforce UTF-8 encoding. This fixes the issue and does not seem to introduce any regressions. Tested locally and it now parses the name correctly.

@eliandoran eliandoran force-pushed the bugfix/upload_filename_encoding branch from aead7f3 to 02a5f4b Compare August 14, 2022 01:12
@eliandoran eliandoran force-pushed the bugfix/upload_filename_encoding branch from 02a5f4b to d1f3ce0 Compare August 14, 2022 01:14
@eliandoran eliandoran changed the title Fix UTF-8 file name encoding for uploads Fix UTF-8 file name encoding for uploads (fixes #3013) Aug 14, 2022
@eliandoran
Copy link
Sponsor Collaborator Author

@zadam , if you're not comfortable with enforcing the UTF-8 encoding (since it's somewhat of an upstream issue), we could try to upgrade to the non-LTS version of Multer, but from what I understand it breaks compatibility with some older versions.

@eliandoran eliandoran requested a review from zadam August 14, 2022 01:20
@zadam zadam merged commit bb37340 into zadam:master Aug 14, 2022
@eliandoran eliandoran deleted the bugfix/upload_filename_encoding branch November 6, 2022 17:09
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 this pull request may close these issues.

None yet

2 participants