Skip to content

Commit

Permalink
Fix decoding filenames from Chrome/Firefox
Browse files Browse the repository at this point in the history
fixes #252
  • Loading branch information
dougwilson committed Jun 4, 2023
1 parent 399a4dc commit a786412
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions HISTORY.md
@@ -1,6 +1,7 @@
unreleased
==========

* Fix decoding filenames from Chrome/Firefox
* Fix form parsing when no `part` event listener added
* deps: http-errors@2.0.0
- deps: depd@2.0.0
Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -836,7 +836,7 @@ function parseFilename(headerValue) {

var filename = m[1] || m[2] || '';
filename = filename.replace(/%22|\\"/g, '"');
filename = filename.replace(/&#([\d]{4});/g, function(m, code) {
filename = filename.replace(/&#([0-9]{1,5});/g, function(m, code) {
return String.fromCharCode(code);
});
return filename.substr(filename.lastIndexOf('\\') + 1);
Expand Down
16 changes: 16 additions & 0 deletions test/fixture/http/special-chars-in-filename/issue-252-chrome.http
@@ -0,0 +1,16 @@
POST /upload HTTP/1.1
Host: localhost:8080
Content-Length: 363
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarytyE4wkKlZ5CQJVTG

------WebKitFormBoundarytyE4wkKlZ5CQJVTG
Content-Disposition: form-data; name="title"

Weird filename
------WebKitFormBoundarytyE4wkKlZ5CQJVTG
Content-Disposition: form-data; name="upload"; filename="JΛ̊KE_2023-02-25T16:44:24.129Z.txt"
Content-Type: text/plain

I am a text file with a funky name!

------WebKitFormBoundarytyE4wkKlZ5CQJVTG--
12 changes: 12 additions & 0 deletions test/fixture/js/special-chars-in-filename.js
Expand Up @@ -20,6 +20,18 @@ var webkit = " ? % * | \" < > . ? ; ' @ # $ ^ & ( ) - _ = + { } [ ] ` ~.txt";
var ffOrIe = " ? % * | \" < > . ☃ ; ' @ # $ ^ & ( ) - _ = + { } [ ] ` ~.txt";

module.exports = {
'issue-252-chrome.http' : [
{
type: 'field',
name: 'title',
value: 'Weird filename'
},
{
type: 'file',
name: 'upload',
filename: 'JΛ̊KE_2023-02-25T16:44:24.129Z.txt'
}
],
'osx-chrome-13.http' : expect(webkit),
'osx-firefox-3.6.http' : expect(ffOrIe),
'osx-safari-5.http' : expect(webkit),
Expand Down

0 comments on commit a786412

Please sign in to comment.