Skip to content

Commit

Permalink
lib: catch busboy parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusU committed Sep 19, 2015
1 parent 1d456cf commit f0d1f20
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/make-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function makeMiddleware (setup) {

})

busboy.on('error', function (err) { abortWithError(err) })
busboy.on('partsLimit', function () { abortWithCode('LIMIT_PART_COUNT') })
busboy.on('filesLimit', function () { abortWithCode('LIMIT_FILE_COUNT') })
busboy.on('fieldsLimit', function () { abortWithCode('LIMIT_FIELD_COUNT') })
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"dependencies": {
"append-field": "^0.1.0",
"busboy": "^0.2.9",
"busboy": "^0.2.11",
"concat-stream": "^1.5.0",
"mkdirp": "^0.5.1",
"object-assign": "^3.0.0",
Expand Down
26 changes: 26 additions & 0 deletions test/error-handling.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,30 @@ describe('Error Handling', function () {
done()
})
})

it('should report errors from busboy parsing', function (done) {
var req = new stream.PassThrough()
var storage = multer.memoryStorage()
var upload = multer({ storage: storage }).single('tiny0')
var boundary = 'AaB03x'
var body = [
'--' + boundary,
'Content-Disposition: form-data; name="tiny0"; filename="test.txt"',
'Content-Type: text/plain',
'',
'test without end boundary'
].join('\r\n')

req.headers = {
'content-type': 'multipart/form-data; boundary=' + boundary,
'content-length': body.length
}

req.end(body)

upload(req, null, function (err) {
assert.equal(err.message, 'Unexpected end of multipart data')
done()
})
})
})

0 comments on commit f0d1f20

Please sign in to comment.