From eaaab559fa9212cbd4fff933a2e5e68f69d54f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Nu=C3=B1ez?= Date: Thu, 24 Nov 2022 11:35:33 -0300 Subject: [PATCH] Fix content type case issue on regex parse --- index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index aa5c684..264a7e6 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,7 @@ function getBoundary(event) { module.exports.parse = (event, spotText) => { const boundary = getBoundary(event); const result = {}; + const contentTypeRegex = /Content-Type:\s.+/gi; event.body .split(boundary) .forEach(item => { @@ -19,9 +20,9 @@ module.exports.parse = (event, spotText) => { result[item.match(/name=".+";/g)[0].slice(6, -2)] = { type: 'file', filename: item.match(/filename=".+"/g)[0].slice(10, -1), - contentType: item.match(/Content-Type:\s.+/g)[0].slice(14), - content: spotText? Buffer.from(item.slice(item.search(/Content-Type:\s.+/g) + item.match(/Content-Type:\s.+/g)[0].length + 4, -4), 'binary'): - item.slice(item.search(/Content-Type:\s.+/g) + item.match(/Content-Type:\s.+/g)[0].length + 4, -4), + contentType: item.match()[0].slice(14), + content: spotText? Buffer.from(item.slice(item.search(contentTypeRegex) + item.match(contentTypeRegex)[0].length + 4, -4), 'binary'): + item.slice(item.search(contentTypeRegex) + item.match(contentTypeRegex)[0].length + 4, -4), }; } else if (/name=".+"/g.test(item)){ result[item.match(/name=".+"/g)[0].slice(6, -1)] = item.slice(item.search(/name=".+"/g) + item.match(/name=".+"/g)[0].length + 4, -4);