richardgirges / express-fileupload

Simple express file upload middleware that wraps around busboy
MIT License
1.53k stars 260 forks source link

TypeError - Cannot read properties of undefined (reading 'includes') in lib/isEligibleRequest.js #364

Closed dimitri-gigot closed 10 months ago

dimitri-gigot commented 10 months ago

Hi,

Since version 1.4.2 , this error appeared in our Sentry. Seems easy to fix by checking if "contType" exist before trying to see if it "includes('boundary=')".

I'm not used to posting issues or trying to fix them but i'll do my best 😄

king-d-dev commented 10 months ago

+1

king-d-dev commented 10 months ago

here's a PR that addresses the bug https://github.com/richardgirges/express-fileupload/pull/366 cc @richardgirges

RomanBurunkov commented 10 months ago

Hi,

I have another idea regarding this. Since it can be several cases which lead to the exception, what if just wrap the final function in try/catch, instead of trying to consider all possible options?

module.exports = (req) => {
  try {
    return hasBody(req) && hasAcceptableMethod(req) && hasAcceptableContentType(req);
  } catch (e) {
    return false;
  }
};
RomanBurunkov commented 10 months ago

Fixed with the PR #367 Published new version 1.4.3