+
Skip to content

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

@xet7

Description

@xet7

Moved to here from wefork#87

@yatusiter can you submit this as pull request to devel branch, so it shows you as author of fix in git history, and I can add you as contributor to changelog?

Originally by @yatusiter

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

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);
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载