diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2022-10-05 18:31:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-05 12:31:36 -0400 |
commit | b487027b4576332a0f0f818e7e8feda5dcc04d15 (patch) | |
tree | 554ac2cd27ceaba6f24ca55ac4042a5d498e026f /ext/fetch/21_formdata.js | |
parent | 0b016a7fb8639ce49603c8c339539174b191a4b1 (diff) |
refactor(ext/fetch): simplify parseContentDisposition (#16162)
Replaced `forEach`, `map`, `filter`, `map` with a single `for` loop
Diffstat (limited to 'ext/fetch/21_formdata.js')
-rw-r--r-- | ext/fetch/21_formdata.js | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/ext/fetch/21_formdata.js b/ext/fetch/21_formdata.js index 72f83a860..5532cc5a3 100644 --- a/ext/fetch/21_formdata.js +++ b/ext/fetch/21_formdata.js @@ -16,12 +16,9 @@ const { Blob, BlobPrototype, File, FilePrototype } = globalThis.__bootstrap.file; const { - ArrayPrototypeMap, ArrayPrototypePush, ArrayPrototypeSlice, ArrayPrototypeSplice, - ArrayPrototypeFilter, - ArrayPrototypeForEach, Map, MapPrototypeGet, MapPrototypeSet, @@ -335,20 +332,17 @@ /** @type {Map<string, string>} */ const params = new Map(); // Forced to do so for some Map constructor param mismatch - ArrayPrototypeForEach( - ArrayPrototypeMap( - ArrayPrototypeFilter( - ArrayPrototypeMap( - ArrayPrototypeSlice(StringPrototypeSplit(value, ";"), 1), - (s) => StringPrototypeSplit(StringPrototypeTrim(s), "="), - ), - (arr) => arr.length > 1, - ), - ([k, v]) => [k, StringPrototypeReplace(v, /^"([^"]*)"$/, "$1")], - ), - ([k, v]) => MapPrototypeSet(params, k, v), - ); - + const values = ArrayPrototypeSlice(StringPrototypeSplit(value, ";"), 1); + for (let i = 0; i < values.length; i++) { + const entries = StringPrototypeSplit(StringPrototypeTrim(values[i]), "="); + if (entries.length > 1) { + MapPrototypeSet( + params, + entries[0], + StringPrototypeReplace(entries[1], /^"([^"]*)"$/, "$1"), + ); + } + } return params; } |