freesoftwarefactory / parse-multipart

A javascript/nodejs multipart/form-data parser which operates on raw data.
MIT License
48 stars 79 forks source link

Improve parsing of content-type in Parse.process() #22

Closed samhuk closed 3 years ago

samhuk commented 5 years ago

Steer away from unsafe array access via regex, i.e.:

const contentTypeRegexResult = (new RegExp(/[cC]ontent-[tT]ype:\s*(.*)/))
  .exec(part.info)
const contentType = contentTypeRegexResult
  && contentTypeRegexResult[1]
  && typeof contentTypeRegexResult[1] === 'string'
    ? contentTypeRegexResult[1].trim().replace(/[^a-z-\/]/g, '')
    : undefined