filepond icon indicating copy to clipboard operation
filepond copied to clipboard

Foreign character failure - unescape(encodeURIComponent(options.headers[key])); [Bug]

Open lemonbob opened this issue 1 year ago • 4 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Have you updated FilePond and its plugins?

  • [X] I have updated FilePond and its plugins

Describe the bug

In sendRequest.js, the deprecated unescape() method is called on a encodeURIComponent string. The two methods are not compatible with one another and creates an error in PATCH requests when using foreign characters in the payload.

Reproduction

Upload a large file (requiring a PATCH request) that has foreign characters e.g. 'Test_错误获取风险数据.jpg'

Environment

- Device:Dell Latitude 5430
- OS:Windows 11
- Browser: Chrome 123.0.6312.86 (Official Build) (64-bit)

lemonbob avatar Apr 02 '24 13:04 lemonbob

Thanks for reporting. So this doesn't happen when uploading without PATCH?

rikschennink avatar Apr 03 '24 09:04 rikschennink

Hi Rik,

It relates to a header property Upload-Name. This only appears in the PATCH call and not the base networkcall if the file is small. When the filename has foreign characters, the "encodeURIComponent" and "unescape" cause the below corruption of file name which throws an error. It is browser related too, depending on how unescape has been implemented. Latest Chrome has the error.

As I understand it, unescape is deprecated and non-standard, which is possibly why this error has only recently happened.

In the below 24098_错误获取风险数据.png gets corrupted.

image

I believe it relates to this code here in sendRequest.js, where unescape and encodeURIComponent are incompatible. One encodes as unicode, the other is hexadecimal.

image

lemonbob avatar Apr 03 '24 11:04 lemonbob

@lemonbob thanks for clarifying 🙏

rikschennink avatar May 14 '24 06:05 rikschennink