Skip to content

Commit a786412

Browse files
committed
Fix decoding filenames from Chrome/Firefox
fixes #252
1 parent 399a4dc commit a786412

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

HISTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
unreleased
22
==========
33

4+
* Fix decoding filenames from Chrome/Firefox
45
* Fix form parsing when no `part` event listener added
56
67

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ function parseFilename(headerValue) {
836836

837837
var filename = m[1] || m[2] || '';
838838
filename = filename.replace(/%22|\\"/g, '"');
839-
filename = filename.replace(/&#([\d]{4});/g, function(m, code) {
839+
filename = filename.replace(/&#([0-9]{1,5});/g, function(m, code) {
840840
return String.fromCharCode(code);
841841
});
842842
return filename.substr(filename.lastIndexOf('\\') + 1);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
POST /upload HTTP/1.1
2+
Host: localhost:8080
3+
Content-Length: 363
4+
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarytyE4wkKlZ5CQJVTG
5+
6+
------WebKitFormBoundarytyE4wkKlZ5CQJVTG
7+
Content-Disposition: form-data; name="title"
8+
9+
Weird filename
10+
------WebKitFormBoundarytyE4wkKlZ5CQJVTG
11+
Content-Disposition: form-data; name="upload"; filename="JΛ̊KE_2023-02-25T16:44:24.129Z.txt"
12+
Content-Type: text/plain
13+
14+
I am a text file with a funky name!
15+
16+
------WebKitFormBoundarytyE4wkKlZ5CQJVTG--

test/fixture/js/special-chars-in-filename.js

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ var webkit = " ? % * | \" < > . ? ; ' @ # $ ^ & ( ) - _ = + { } [ ] ` ~.txt";
2020
var ffOrIe = " ? % * | \" < > . ☃ ; ' @ # $ ^ & ( ) - _ = + { } [ ] ` ~.txt";
2121

2222
module.exports = {
23+
'issue-252-chrome.http' : [
24+
{
25+
type: 'field',
26+
name: 'title',
27+
value: 'Weird filename'
28+
},
29+
{
30+
type: 'file',
31+
name: 'upload',
32+
filename: 'JΛ̊KE_2023-02-25T16:44:24.129Z.txt'
33+
}
34+
],
2335
'osx-chrome-13.http' : expect(webkit),
2436
'osx-firefox-3.6.http' : expect(ffOrIe),
2537
'osx-safari-5.http' : expect(webkit),

0 commit comments

Comments
 (0)