Skip to content

Commit 98028e9

Browse files
Merge pull request #367 from RomanBurunkov/master
Fix: Cannot read properties of undefined (reading 'includes').
2 parents fbee074 + a2ab675 commit 98028e9

File tree

4 files changed

+97
-76
lines changed

4 files changed

+97
-76
lines changed

lib/isEligibleRequest.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ const hasAcceptableContentType = (req) => {
3737
* @param {Object} req Express req object
3838
* @returns {Boolean}
3939
*/
40-
module.exports = (req) => hasBody(req) && hasAcceptableMethod(req) && hasAcceptableContentType(req);
40+
module.exports = (req) => {
41+
try {
42+
return hasBody(req) && hasAcceptableMethod(req) && hasAcceptableContentType(req);
43+
} catch (e) {
44+
return false;
45+
}
46+
};

package-lock.json

Lines changed: 77 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "express-fileupload",
3-
"version": "1.4.2",
3+
"version": "1.4.3",
44
"author": "Richard Girges <[email protected]>",
55
"description": "Simple express file upload middleware that wraps around Busboy",
66
"main": "./lib/index",

test/isEligibleRequest.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,16 @@ describe('isEligibleRequest function tests', () => {
113113
const result = isEligibleRequest(req);
114114
assert.equal(result, false);
115115
});
116+
it('should return false if the request is empty or not provided', () => {
117+
const result = isEligibleRequest();
118+
assert.equal(result, false);
119+
});
120+
it('should return false if content-type is not specified.', () => {
121+
const req = {
122+
method: 'POST',
123+
headers: { 'content-length': '768751' }
124+
};
125+
const result = isEligibleRequest(req);
126+
assert.equal(result, false);
127+
});
116128
});

0 commit comments

Comments
 (0)