Skip to content

Commit

Permalink
Merge pull request #367 from RomanBurunkov/master
Browse files Browse the repository at this point in the history
Fix: Cannot read properties of undefined (reading 'includes').
  • Loading branch information
RomanBurunkov authored Nov 21, 2023
2 parents fbee074 + a2ab675 commit 98028e9
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 76 deletions.
8 changes: 7 additions & 1 deletion lib/isEligibleRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ const hasAcceptableContentType = (req) => {
* @param {Object} req Express req object
* @returns {Boolean}
*/
module.exports = (req) => hasBody(req) && hasAcceptableMethod(req) && hasAcceptableContentType(req);
module.exports = (req) => {
try {
return hasBody(req) && hasAcceptableMethod(req) && hasAcceptableContentType(req);
} catch (e) {
return false;
}
};
151 changes: 77 additions & 74 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-fileupload",
"version": "1.4.2",
"version": "1.4.3",
"author": "Richard Girges <[email protected]>",
"description": "Simple express file upload middleware that wraps around Busboy",
"main": "./lib/index",
Expand Down
12 changes: 12 additions & 0 deletions test/isEligibleRequest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,16 @@ describe('isEligibleRequest function tests', () => {
const result = isEligibleRequest(req);
assert.equal(result, false);
});
it('should return false if the request is empty or not provided', () => {
const result = isEligibleRequest();
assert.equal(result, false);
});
it('should return false if content-type is not specified.', () => {
const req = {
method: 'POST',
headers: { 'content-length': '768751' }
};
const result = isEligibleRequest(req);
assert.equal(result, false);
});
});

0 comments on commit 98028e9

Please sign in to comment.