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

Fix: Cannot read properties of undefined (reading 'includes'). #367

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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);
});
});