Skip to content

Commit

Permalink
Fixes expressjs#1233. Makes multer handle missing field names.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoz committed Apr 23, 2024
1 parent ddb65bd commit e0c4ae3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/make-middleware.js
Expand Up @@ -87,6 +87,8 @@ function makeMiddleware (setup) {

// handle files
busboy.on('file', function (fieldname, fileStream, { filename, encoding, mimeType }) {
if (fieldname == null) return abortWithCode('MISSING_FIELD_NAME')

// don't attach to the files object, if there is no file
if (!filename) return fileStream.resume()

Expand Down
13 changes: 13 additions & 0 deletions test/error-handling.js
Expand Up @@ -175,6 +175,19 @@ describe('Error Handling', function () {
})
})

it('should notify of missing field name', function (done) {
var form = new FormData()
var storage = multer.memoryStorage()
var parser = multer({ storage: storage }).single('small0')

form.append('', util.file('small0.dat'))

util.submitForm(parser, form, function (err, req) {
assert.strictEqual(err.code, 'MISSING_FIELD_NAME')
done()
})
})

it('should report errors from storage engines', function (done) {
var storage = multer.memoryStorage()

Expand Down

0 comments on commit e0c4ae3

Please sign in to comment.