From ac2abe5b1e5e872a587da3593e8d764512f05438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Thu, 28 Jan 2010 17:16:18 +0100 Subject: [PATCH 1/9] Bugfix: Handle Content-Type headers with charset Some HTTP clients include a charset parameter in the Content-Type, e.g: multipart/form-data; charset=utf-8; boundary=0xKhTmLbOuNdArY This patch makes the multipart parser more forgiving towards unexpected information included in the Content-Type header. --- lib/multipart.js | 8 ++++++-- test/mjsunit/test-multipart.js | 10 +++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) 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); From 704f394c6671af5b981900fc3666f1b97ef580a9 Mon Sep 17 00:00:00 2001 From: Micheil Smith Date: Sat, 30 Jan 2010 18:11:43 +1100 Subject: [PATCH 2/9] Adding output of Platform information into the test runner --- tools/test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/test.py b/tools/test.py index 74bde14abf..607a62e614 100755 --- a/tools/test.py +++ b/tools/test.py @@ -101,6 +101,7 @@ class ProgressIndicator(object): # ...and then reraise the exception to bail out raise self.Done() + print "\r\nPlatform: {0} {1}".format(platform.system(), platform.release()) return not self.failed def RunSingle(self): From 7a755e04a94c1a58bf88c3643c1dd4a027865dbf Mon Sep 17 00:00:00 2001 From: Jonas Pfenniger Date: Sat, 30 Jan 2010 20:58:24 -0800 Subject: [PATCH 3/9] Was using the old node object to get the int from the constant. --- src/node_child_process.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_child_process.cc b/src/node_child_process.cc index 78d5c5c5be..95d363e473 100644 --- a/src/node_child_process.cc +++ b/src/node_child_process.cc @@ -148,7 +148,7 @@ Handle ChildProcess::Kill(const Arguments& args) { } else if (args[0]->IsString()) { Local signame = args[0]->ToString(); Local process = Context::GetCurrent()->Global(); - Local node_obj = process->Get(String::NewSymbol("node"))->ToObject(); + Local node_obj = process->Get(String::NewSymbol("process"))->ToObject(); Local sig_v = node_obj->Get(signame); if (!sig_v->IsNumber()) { From 9f5643f427dd507ebe696fb1550cedd4b5af3705 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sat, 30 Jan 2010 23:22:34 -0800 Subject: [PATCH 4/9] Reorganize the start-up process - assign 'GLOBAL' (and now 'global') inside src/node.js - position for eventually allowing replacements to src/node.js for people like Kris Kowal who want the nice libev and libeio bindings but not necessarily node's choices of modules or promises. --- src/node.cc | 77 ++++++++++++++++++++++++++++++++--------------------- src/node.js | 9 +++++-- 2 files changed, 54 insertions(+), 32 deletions(-) diff --git a/src/node.cc b/src/node.cc index 8796047c6a..00d1c8ceef 100644 --- a/src/node.cc +++ b/src/node.cc @@ -198,7 +198,6 @@ ssize_t DecodeBytes(v8::Handle val, enum encoding encoding) { ssize_t DecodeWrite(char *buf, size_t buflen, v8::Handle val, enum encoding encoding) { - size_t i; HandleScope scope; // XXX @@ -366,18 +365,17 @@ static void ReportException(TryCatch *try_catch, bool show_line = false) { } // Executes a str within the current v8 context. -Handle ExecuteString(v8::Handle source, - v8::Handle filename) { +Local ExecuteString(Local source, Local filename) { HandleScope scope; TryCatch try_catch; - Handle