Skip to content

Commit 7c7416a

Browse files
committed
Improved Content-Disposition parsing (added support for 'token' definition of the 'disp-extension-parm' rule, RFC 2616 section 19.5.1)
1 parent b7ef166 commit 7c7416a

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

lib/incoming_form.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ IncomingForm.prototype._initMultipart = function(boundary) {
352352
headerField = headerField.toLowerCase();
353353
part.headers[headerField] = headerValue;
354354

355-
var m = headerValue.match(/\bname="([^"]+)"/i);
355+
// matches either a quoted-string or a token (RFC 2616 section 19.5.1)
356+
var m = headerValue.match(/\bname=("([^"]+)"|([^\(\)<>@,;:\\"\/\[\]\?=\{\}\s\t/]+))/i);
356357
if (headerField == 'content-disposition') {
357358
if (m) {
358359
part.name = m[1];
@@ -421,7 +422,8 @@ IncomingForm.prototype._initMultipart = function(boundary) {
421422
};
422423

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

427429
var filename = m[1].substr(m[1].lastIndexOf('\\') + 1);

0 commit comments

Comments
 (0)