Content-Transfer-Encoding set on multipart parts is ignored #127

Open
moses-palmer opened this Issue Jan 26, 2012 · 3 comments

Comments

Projects
None yet
3 participants

I noticed that some tests in our test suite failed because the mock server received invalid binary data.

The test involves a multipart/form-data request sending both "text/plain; encoding=utf-8" fields and a custom MIME type with Content-Transfer-Encoding set to "binary". The binary data contains a few "\xFE" characters, and those especially would be corrupted.

I think the test case is valid. Content-Transfer-Encoding appears to be applicable to parts.

I made a patch that adds encoding to parts, and uses that in favour of the form encoding if present. I will try to attach it if that is possible on github.

No, that was not possible, so I will simply add the patch as a comment.

From 59c3284 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Moses=20Palm=C3=A9r?= moses@blockmastersecurity.com
Date: Thu, 26 Jan 2012 11:58:09 +0100
Subject: [PATCH] Do not ignore Content-Transfer-Encoding of parts


lib/incoming_form.js | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/lib/incoming_form.js b/lib/incoming_form.js
index 7b1ddaf..9f3c0b3 100644
--- a/lib/incoming_form.js
+++ b/lib/incoming_form.js
@@ -164,7 +164,7 @@ IncomingForm.prototype.handlePart = function(part) {

if (part.filename === undefined) {
var value = ''

  •  , decoder = new StringDecoder(this.encoding);
    
  •  , decoder = new StringDecoder(part.encoding || this.encoding);
    

    part.on('data', function(buffer) {
    self._fieldsSize += buffer.length;
    @@ -271,6 +271,7 @@ IncomingForm.prototype._initMultipart = function(boundary) {
    part.name = null;
    part.filename = null;
    part.mime = null;

  • part.encoding = null;
    headerField = '';
    headerValue = '';
    };
    @@ -296,6 +297,8 @@ IncomingForm.prototype._initMultipart = function(boundary) {
    part.filename = self._fileName(headerValue);
    } else if (headerField == 'content-type') {
    part.mime = headerValue;

  • } else if (headerField == 'content-transfer-encoding') {

  •  part.encoding = headerValue;
    

    }

    headerField = '';

    1.7.5.1

mscdex commented Jan 26, 2012

A pull request would probably be best.

Owner

felixge commented Jan 27, 2012

A pull request would be great. Please also add a test of some kind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment