diff --git a/index.js b/index.js index 1dbfaacb..42cfcab0 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,9 @@ function Multer (options) { } this.limits = options.limits + if (this.limits && this.limits.fileSize != null && !Number.isInteger(this.limits.fileSize)) { + throw new TypeError('Expected limits.fileSize to be an integer') + } this.preservePath = options.preservePath this.defParamCharset = options.defParamCharset || 'latin1' this.fileFilter = options.fileFilter || allowAll diff --git a/test/error-handling.js b/test/error-handling.js index 597e8039..30b53b10 100644 --- a/test/error-handling.js +++ b/test/error-handling.js @@ -459,4 +459,16 @@ describe('Error Handling', function () { done() }) }) + + it('should throw TypeError when fileSize limit is a float', function () { + assert.throws(function () { + multer({ limits: { fileSize: 1024.5 } }) + }, TypeError) + }) + + it('should accept integer fileSize limit', function () { + assert.doesNotThrow(function () { + multer({ limits: { fileSize: 1024 } }) + }) + }) })