Skip to content

Commit 35a3272

Browse files
mmozctcpip
authored andcommitted
Fixes #1233. Makes multer handle missing field names.
1 parent f897007 commit 35a3272

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/make-middleware.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ function makeMiddleware (setup) {
101101

102102
// handle files
103103
busboy.on('file', function (fieldname, fileStream, { filename, encoding, mimeType }) {
104+
if (fieldname == null) return abortWithCode('MISSING_FIELD_NAME')
105+
104106
// don't attach to the files object, if there is no file
105107
if (!filename) return fileStream.resume()
106108

test/error-handling.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@ describe('Error Handling', function () {
175175
})
176176
})
177177

178+
it('should notify of missing field name', function (done) {
179+
var form = new FormData()
180+
var storage = multer.memoryStorage()
181+
var parser = multer({ storage: storage }).single('small0')
182+
183+
form.append('', util.file('small0.dat'))
184+
185+
util.submitForm(parser, form, function (err, req) {
186+
assert.strictEqual(err.code, 'MISSING_FIELD_NAME')
187+
done()
188+
})
189+
})
190+
178191
it('should report errors from storage engines', function (done) {
179192
var storage = multer.memoryStorage()
180193

0 commit comments

Comments
 (0)