Skip to content
This repository
  • 3 commits
  • 3 files changed
  • 0 comments
  • 1 contributor
Jun 16, 2010
Felix Geisendörfer Fix: Handle resume errors c9df5fe
Jun 17, 2010
Felix Geisendörfer Fix: Don't let the world know how stupid IE is
IE6 (and up?) actually sends the full path of the local file that is
being uploaded rather than just the name of it. This patch strips of
any path information from the filename.
0358f0e
Felix Geisendörfer Bump version cd5686b
10  lib/formidable/incoming_form.js
@@ -36,7 +36,13 @@ IncomingForm.prototype.parse = function(req, cb) {
36 36
   };
37 37
 
38 38
   this.resume = function() {
39  
-    req.resume();
  39
+    try {
  40
+      req.resume();
  41
+    } catch (err) {
  42
+      this._error(err);
  43
+      return false;
  44
+    }
  45
+
40 46
     return true;
41 47
   };
42 48
 
@@ -239,7 +245,7 @@ IncomingForm.prototype._initMultipart = function(boundary) {
239 245
           }
240 246
 
241 247
           if (m = headerValue.match(/filename="([^"]+)"/i)) {
242  
-            part.filename = m[1];
  248
+            part.filename = m[1].substr(m[1].lastIndexOf('\\') + 1);
243 249
           }
244 250
         } else if (headerField == 'content-type') {
245 251
           part.mime = headerValue;
2  package.json
... ...
@@ -1,5 +1,5 @@
1 1
 { "name" : "formidable"
2  
-, "version": "0.9.0"
  2
+, "version": "0.9.1"
3 3
 , "dependencies": {"gently": ">=0.7.0"}
4 4
 , "directories" : { "lib" : "./lib/formidable" }
5 5
 , "main" : "./lib/formidable/index"
19  test/simple/test-incoming-form.js
@@ -63,6 +63,19 @@ test(function parse() {
63 63
     gently.expect(REQ, 'resume');
64 64
     assert.strictEqual(form.resume(), true);
65 65
   })();
  66
+
  67
+  (function testResumeException() {
  68
+    var ERR = new Error('dasdsa');
  69
+    gently.expect(REQ, 'resume', function() {
  70
+      throw ERR;
  71
+    });
  72
+
  73
+    gently.expect(form, '_error', function(err) {
  74
+      assert.strictEqual(err, ERR);
  75
+    });
  76
+
  77
+    assert.strictEqual(form.resume(), false);
  78
+  })();
66 79
   
67 80
   (function testEmitError() {
68 81
     var ERR = new Error('something bad happened');
@@ -365,12 +378,12 @@ test(function _initMultipart() {
365 378
     gently.expect(form, 'onPart', function(part) {
366 379
       assert.deepEqual
367 380
         ( part.headers
368  
-        , { 'content-disposition': 'form-data; name="field2"; filename="file1.txt"'
  381
+        , { 'content-disposition': 'form-data; name="field2"; filename="C:\\Documents and Settings\\IE\\Must\\Die\\Sunset.jpg"'
369 382
           , 'content-type': 'text/plain'
370 383
           }
371 384
         );
372 385
       assert.equal(part.name, 'field2');
373  
-      assert.equal(part.filename, 'file1.txt');
  386
+      assert.equal(part.filename, 'Sunset.jpg');
374 387
       assert.equal(part.mime, 'text/plain');
375 388
 
376 389
       gently.expect(part, 'emit', function(event, b) {
@@ -385,7 +398,7 @@ test(function _initMultipart() {
385 398
 
386 399
     PARSER.onPartBegin();
387 400
     PARSER.onHeaderField(new Buffer('content-disposition'), 0, 19);
388  
-    PARSER.onHeaderValue(new Buffer('form-data; name="field2"; filename="file1.txt"'), 0, 46);
  401
+    PARSER.onHeaderValue(new Buffer('form-data; name="field2"; filename="C:\\Documents and Settings\\IE\\Must\\Die\\Sunset.jpg"'), 0, 85);
389 402
     PARSER.onHeaderField(new Buffer('Content-Type'), 0, 12);
390 403
     PARSER.onHeaderValue(new Buffer('text/plain'), 0, 10);
391 404
     PARSER.onPartData(new Buffer('... contents of file1.txt ...'), 0, 29);

No commit comments for this range

Something went wrong with that request. Please try again.