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

Download file(unicode filename) action cause server process crashed with exception. #87

Closed
yatusiter opened this issue Jan 24, 2017 · 4 comments

Comments

@yatusiter
Copy link

yatusiter commented Jan 24, 2017

When click download from card with unicode(Chinese) filename (upload is OK), the server process crash with following exception :

./wekan/bundle/programs/server/node_modules/fibers/future.js:280
throw(ex);
^
TypeError: The header content contains invalid characters
at ServerResponse.OutgoingMessage.setHeader (http.js:733:13)
at ServerResponse.res.setHeader (/home/sjyb/install/wekan/bundle/programs/server/npm/node_modules/meteor/webapp/node_modules/connect/lib/patch.js:134:22)
at packages/cfs_http-methods/http.methods.server.api.js:599:1
at Function..each..forEach (packages/underscore/underscore.js:113:1)
at packages/cfs_http-methods/http.methods.server.api.js:595:1


After googled around, it's seems the HTTP header "Content-Disposition" cannot accept unicode encoding characters, and should be binary or URI encoded.

https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
https://my.oschina.net/jsan/blog/180333

Temporary fix with this solution:
#bundle/programs/server/packages/cfs_access-point.js add after line 444, FS.HTTP.Handlers.Get function:

const originalHandler = FS.HTTP.Handlers.Get;
FS.HTTP.Handlers.Get = function (ref) {
//console.log(ref.filename);
  try {
     var userAgent = (this.requestHeaders['user-agent']||'').toLowerCase();

        if(userAgent.indexOf('msie') >= 0 || userAgent.indexOf('chrome') >= 0) {
            ref.filename =  encodeURIComponent(ref.filename);
        } else if(userAgent.indexOf('firefox') >= 0) {
            ref.filename = new Buffer(ref.filename).toString('binary');
        } else {
            /* safari*/
            ref.filename = new Buffer(ref.filename).toString('binary');
        }   
   } catch (ex){
        ref.filename = 'tempfix';
   } 
   return originalHandler.call(this, ref);
};

@Daniel231
Copy link

@yatusiter i tried your temporary fix but i cant edit the package, can you be more specific where did you add the code? (i mean after which function)

@yatusiter
Copy link
Author

@Daniel231 just after the original definiton of FS.HTTP.Handlers.Get

bundle/programs/server/packages/cfs_access-point.js add after line 444, FS.HTTP.Handlers.Get function:

@Daniel231
Copy link

@yatusiter Success! thx :D

@xet7
Copy link
Member

xet7 commented Feb 6, 2017

Moved to wekan#784

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

No branches or pull requests

3 participants