Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes expressjs/multer#553 . Makes multer handle missing field names. #913

Merged
merged 2 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/make-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function makeMiddleware (setup) {

// handle text field data
busboy.on('field', function (fieldname, value, fieldnameTruncated, valueTruncated) {
if (!fieldname) return abortWithCode('LIMIT_MISSING_FIELD_NAME')
LinusU marked this conversation as resolved.
Show resolved Hide resolved
if (fieldnameTruncated) return abortWithCode('LIMIT_FIELD_KEY')
if (valueTruncated) return abortWithCode('LIMIT_FIELD_VALUE', fieldname)

Expand Down
3 changes: 2 additions & 1 deletion lib/multer-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var errorMessages = {
LIMIT_FIELD_KEY: 'Field name too long',
LIMIT_FIELD_VALUE: 'Field value too long',
LIMIT_FIELD_COUNT: 'Too many fields',
LIMIT_UNEXPECTED_FILE: 'Unexpected field'
LIMIT_UNEXPECTED_FILE: 'Unexpected field',
LIMIT_MISSING_FIELD_NAME: 'Field name missing'
LinusU marked this conversation as resolved.
Show resolved Hide resolved
}

function MulterError (code, field) {
Expand Down
27 changes: 27 additions & 0 deletions test/error-handling.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,33 @@ describe('Error Handling', function () {
})
})

it('should notify of missing field name', 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',
'',
'test content',
'--' + 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.strictEqual(err.code, 'LIMIT_MISSING_FIELD_NAME')
LinusU marked this conversation as resolved.
Show resolved Hide resolved
done()
})
})

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

Expand Down