Skip to content
This repository
  • 8 commits
  • 6 files changed
  • 4 comments
  • 3 contributors
Oct 24, 2010
Felix Geisendörfer Fix comma error introduced in refactoring df18901
Oct 30, 2010
Felix Geisendörfer Better project description
Also added a paragraph about the state of the module with a tiny advertisment for
transloadit ; ).
0cba820
Nov 12, 2010
Felix Geisendörfer Fix global variable leak
See report here: 792503a#L0R252
82050b7
Nov 25, 2010
Felix Geisendörfer Make Makefile more portable 66fbaae
Dec 07, 2010
Aaron Heckmann fix global var leaks (comma last issue) 8e6cb2e
Dec 15, 2010
Jacek Becela Remove parsing of optional CRLF epilogoue, change parser so it ignore…
…s everything after last boundary
4800b7f
Felix Geisendörfer Bringing back the old rfc1867 test
The test without the trailing \r\n is now a separate test.
633f0b5
Felix Geisendörfer Bump version 2b02144
4  Makefile
... ...
@@ -1,7 +1,9 @@
  1
+SHELL := /bin/bash
  2
+
1 3
 test:
2 4
 	@find test/{simple,integration,system}/test-*.js | xargs -n 1 -t node
3 5
 
4 6
 clean:
5 7
 	rm test/tmp/*
6 8
 
7  
-.PHONY: test clean
  9
+.PHONY: test clean
11  Readme.md
Source Rendered
@@ -2,7 +2,13 @@
2 2
 
3 3
 ## Purpose
4 4
 
5  
-A node.js module for dealing with web forms.
  5
+A node.js module for parsing form data, especially file uploads.
  6
+
  7
+## Current status
  8
+
  9
+This module was developed for [Transloadit](http://transloadit.com/), a service focused on uploading
  10
+and encoding images and videos. It has been battle-tested against hundreds of GB of file uploads from
  11
+a big variety of clients and is considered production-ready.
6 12
 
7 13
 ## Features
8 14
 
@@ -35,7 +41,8 @@ Note: Formidable requires [gently](http://github.com/felixge/node-gently) to run
35 41
 Parse an incoming file upload.
36 42
 
37 43
     var formidable = require('formidable'),
38  
-        http = require('http')
  44
+        http = require('http'),
  45
+
39 46
         sys = require('sys');
40 47
 
41 48
     http.createServer(function(req, res) {
4  lib/formidable/incoming_form.js
... ...
@@ -1,6 +1,6 @@
1 1
 if (global.GENTLY) require = GENTLY.hijack(require);
2 2
 
3  
-var util = require('./util')
  3
+var util = require('./util'),
4 4
     path = require('path'),
5 5
     File = require('./file'),
6 6
     MultipartParser = require('./multipart_parser').MultipartParser,
@@ -326,7 +326,7 @@ IncomingForm.prototype._initUrlencoded = function() {
326 326
 
327 327
 IncomingForm.prototype._uploadPath = function(filename) {
328 328
   var name = '';
329  
-  for (i = 0; i < 32; i++) {
  329
+  for (var i = 0; i < 32; i++) {
330 330
     name += Math.floor(Math.random() * 16).toString(16);
331 331
   }
332 332
 
22  lib/formidable/multipart_parser.js
... ...
@@ -1,4 +1,4 @@
1  
-var Buffer = require('buffer').Buffer
  1
+var Buffer = require('buffer').Buffer,
2 2
     s = 0,
3 3
     S =
4 4
     { PARSER_UNINITIALIZED: s++,
@@ -250,27 +250,15 @@ MultipartParser.prototype.write = function(buffer) {
250 250
             }
251 251
           } else if (flags & F.LAST_BOUNDARY) {
252 252
             if (c == HYPHEN) {
253  
-              index++;
  253
+              callback('partEnd');
  254
+              callback('end');
  255
+              state = S.END;
254 256
             } else {
255 257
               index = 0;
256 258
             }
257 259
           } else {
258 260
             index = 0;
259 261
           }
260  
-        } else if (index - 2 == boundary.length)  {
261  
-          if (c == CR) {
262  
-            index++;
263  
-          } else {
264  
-            index = 0;
265  
-          }
266  
-        } else if (index - boundary.length == 3)  {
267  
-          index = 0;
268  
-          if (c == LF) {
269  
-            callback('partEnd');
270  
-            callback('end');
271  
-            state = S.END;
272  
-            break;
273  
-          }
274 262
         }
275 263
 
276 264
         if (index > 0) {
@@ -290,6 +278,8 @@ MultipartParser.prototype.write = function(buffer) {
290 278
         }
291 279
 
292 280
         break;
  281
+      case S.END:
  282
+        break;
293 283
       default:
294 284
         return i;
295 285
     }
4  package.json
... ...
@@ -1,6 +1,6 @@
1 1
 { "name" : "formidable",
2  
-  "version": "0.9.9",
  2
+  "version": "0.9.10",
3 3
   "dependencies": {"gently": ">=0.7.0"},
4 4
   "directories" : { "lib" : "./lib/formidable" },
5  
-  "main" : "./lib/formidable/index",
  5
+  "main" : "./lib/formidable/index"
6 6
 }
28  test/fixture/multipart.js
@@ -26,6 +26,34 @@ exports['rfc1867'] =
26 26
     ]
27 27
   };
28 28
 
  29
+exports['noTrailing\r\n'] =
  30
+  { boundary: 'AaB03x',
  31
+    raw:
  32
+      '--AaB03x\r\n'+
  33
+      'content-disposition: form-data; name="field1"\r\n'+
  34
+      '\r\n'+
  35
+      'Joe Blow\r\nalmost tricked you!\r\n'+
  36
+      '--AaB03x\r\n'+
  37
+      'content-disposition: form-data; name="pics"; filename="file1.txt"\r\n'+
  38
+      'Content-Type: text/plain\r\n'+
  39
+      '\r\n'+
  40
+      '... contents of file1.txt ...\r\r\n'+
  41
+      '--AaB03x--',
  42
+    parts:
  43
+    [ { headers: {
  44
+          'content-disposition': 'form-data; name="field1"',
  45
+        },
  46
+        data: 'Joe Blow\r\nalmost tricked you!',
  47
+      },
  48
+      { headers: {
  49
+          'content-disposition': 'form-data; name="pics"; filename="file1.txt"',
  50
+          'Content-Type': 'text/plain',
  51
+        },
  52
+        data: '... contents of file1.txt ...\r',
  53
+      }
  54
+    ]
  55
+  };
  56
+
29 57
 exports['emptyHeader'] =
30 58
   { boundary: 'AaB03x',
31 59
     raw:

Showing you all comments on commits in this comparison.

Aaron Heckmann

Comma first! :p

Felix Geisendörfer
Owner

Well, JSON is fucking stupid for not allowing a trailing comma. But since V8 doesn't care for JavaScript itself it's usually not a problem.

Anyway - I agree, comma-first was nice, but since nobody else seems to embrace it I'd rather go with an accepted convention for my modules.

Aaron Heckmann

Twice in the past two weeks I've been bitten by this exact issue in older code. Yeah, it'd be great if more people began using it. I'm glad I've switched.

Aaron Heckmann

whoop!

Something went wrong with that request. Please try again.