diff --git a/lib/multipart.js b/lib/multipart.js index a5afeff3ba..826be951ee 100644 --- a/lib/multipart.js +++ b/lib/multipart.js @@ -56,11 +56,15 @@ proto.init = function(options) { throw new Error('Content-Type header not set'); } - var boundary = contentType.match(/^multipart\/form-data; ?boundary=(.+)$/i) - if (!boundary) { + if (!contentType.match(/^multipart\/form-data/i)) { throw new Error('Content-Type is not multipart: "'+contentType+'"'); } + var boundary = contentType.match(/boundary=([^;]+)/i) + if (!boundary) { + throw new Error('No boundary in Content-Type header: "'+contentType+'"'); + } + this.boundary = '--'+boundary[1]; this.bytesTotal = req.headers['content-length']; diff --git a/test/mjsunit/test-multipart.js b/test/mjsunit/test-multipart.js index 8de95c370f..0af864a959 100644 --- a/test/mjsunit/test-multipart.js +++ b/test/mjsunit/test-multipart.js @@ -14,7 +14,7 @@ var respond = function(res, text) { requests++; - if (requests == 4) { + if (requests == 5) { server.close(); } @@ -113,6 +113,14 @@ var simpleBadRequest = client.request('POST', '/', { simpleBadRequest.sendBody(fixture.reply, 'binary'); simpleBadRequest.finish(); +var requestWithCharset = client.request('POST', '/', { + 'X-Use-Simple-Api': 'yes', + 'Content-Type': 'multipart/form-data; charset=utf-8; boundary=AaB03x', + 'Content-Length': fixture.reply.length +}); +requestWithCharset.sendBody(fixture.reply, 'binary'); +requestWithCharset.finish(); + process.addListener('exit', function() { puts("done"); assert.equal(2, partsComplete);