Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed parse error since formidable emits "done"

  • Loading branch information...
commit 7434653e0d4a5f44ee2dd83dcc8abe797532707c 1 parent 1ebbc93
@tj tj authored
Showing with 39 additions and 2 deletions.
  1. +7 −2 lib/middleware/bodyParser.js
  2. +32 −0 test/bodyParser.js
View
9 lib/middleware/bodyParser.js
@@ -131,7 +131,8 @@ exports.parse['application/json'] = function(req, options, fn){
exports.parse['multipart/form-data'] = function(req, options, fn){
var form = new formidable.IncomingForm
, query = []
- , files = {};
+ , files = {}
+ , done;
Object.keys(options).forEach(function(key){
form[key] = options[key];
@@ -151,9 +152,13 @@ exports.parse['multipart/form-data'] = function(req, options, fn){
}
});
- form.on('error', fn);
+ form.on('error', function(err){
+ fn(err);
+ done = true;
+ });
form.on('end', function(){
+ if (done) return;
try {
query = query.join('&');
query = qs.parse(query);
View
32 test/bodyParser.js
@@ -190,6 +190,38 @@ describe('connect.bodyParser()', function(){
done();
});
})
+
+ it('should next(err) on multipart failure', function(done){
+ var app = connect();
+
+ app.use(connect.bodyParser());
+
+ app.use(function(req, res){
+ res.end('whoop');
+ });
+
+ app.use(function(err, req, res, next){
+ err.message.should.equal('parser error, 16 of 28 bytes parsed');
+ res.statusCode = 500;
+ res.end();
+ });
+
+ app.request()
+ .post('/')
+ .set('Content-Type', 'multipart/form-data; boundary=foo')
+ .write('--foo\r\n')
+ .write('Content-filename="foo.txt"\r\n')
+ .write('\r\n')
+ .write('some text here')
+ .write('Content-Disposition: form-data; name="text"; filename="bar.txt"\r\n')
+ .write('\r\n')
+ .write('some more text stuff')
+ .write('\r\n--foo--')
+ .end(function(res){
+ res.statusCode.should.equal(500);
+ done();
+ });
+ })
})
})
Please sign in to comment.
Something went wrong with that request. Please try again.