Skip to content

Commit

Permalink
Merge pull request #347 from bitcraftCoLtd/master
Browse files Browse the repository at this point in the history
Improvement on Content-Disposition parsing
  • Loading branch information
felixge committed Sep 9, 2015
2 parents b7ef166 + af6bd44 commit 53bdc35
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/incoming_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,11 @@ IncomingForm.prototype._initMultipart = function(boundary) {
headerField = headerField.toLowerCase();
part.headers[headerField] = headerValue;

var m = headerValue.match(/\bname="([^"]+)"/i);
// matches either a quoted-string or a token (RFC 2616 section 19.5.1)
var m = headerValue.match(/\bname=("([^"]*)"|([^\(\)<>@,;:\\"\/\[\]\?=\{\}\s\t/]+))/i);
if (headerField == 'content-disposition') {
if (m) {
part.name = m[1];
part.name = m[2] || m[3] || '';
}

part.filename = self._fileName(headerValue);
Expand Down Expand Up @@ -421,10 +422,12 @@ IncomingForm.prototype._initMultipart = function(boundary) {
};

IncomingForm.prototype._fileName = function(headerValue) {
var m = headerValue.match(/\bfilename="(.*?)"($|; )/i);
// matches either a quoted-string or a token (RFC 2616 section 19.5.1)
var m = headerValue.match(/\bfilename=("(.*?)"|([^\(\)<>@,;:\\"\/\[\]\?=\{\}\s\t/]+))($|;\s)/i);
if (!m) return;

var filename = m[1].substr(m[1].lastIndexOf('\\') + 1);
var match = m[2] || m[3] || '';
var filename = match.substr(match.lastIndexOf('\\') + 1);
filename = filename.replace(/%22/g, '"');
filename = filename.replace(/&#([\d]{4});/g, function(m, code) {
return String.fromCharCode(code);
Expand Down

0 comments on commit 53bdc35

Please sign in to comment.