(input, mimeType)
| 5359 | } |
| 5360 | for (let i = 0; i < length; ++i) { |
| 5361 | const cp = boundary.charCodeAt(i); |
| 5362 | if (!(cp >= 48 && cp <= 57 || cp >= 65 && cp <= 90 || cp >= 97 && cp <= 122 || cp === 39 || cp === 45 || cp === 95)) { |
| 5363 | return false; |
| 5364 | } |
| 5365 | } |
| 5366 | return true; |
| 5367 | } |
| 5368 | function multipartFormDataParser(input, mimeType) { |
| 5369 | assert(mimeType !== "failure" && mimeType.essence === "multipart/form-data"); |
| 5370 | const boundaryString = mimeType.parameters.get("boundary"); |
| 5371 | if (boundaryString === void 0) { |
| 5372 | return "failure"; |
| 5373 | } |
| 5374 | const boundary = Buffer.from(`--${boundaryString}`, "utf8"); |
| 5375 | const entryList = []; |
| 5376 | const position = { position: 0 }; |
| 5377 | while (input[position.position] === 13 && input[position.position + 1] === 10) { |
| 5378 | position.position += 2; |
| 5379 | } |
| 5380 | let trailing = input.length; |
| 5381 | while (input[trailing - 1] === 10 && input[trailing - 2] === 13) { |
| 5382 | trailing -= 2; |
| 5383 | } |
| 5384 | if (trailing !== input.length) { |
| 5385 | input = input.subarray(0, trailing); |
| 5386 | } |
| 5387 | while (true) { |
| 5388 | if (input.subarray(position.position, position.position + boundary.length).equals(boundary)) { |
| 5389 | position.position += boundary.length; |
| 5390 | } else { |
| 5391 | return "failure"; |
| 5392 | } |
| 5393 | if (position.position === input.length - 2 && bufferStartsWith(input, dd, position) || position.position === input.length - 4 && bufferStartsWith(input, ddcrlf, position)) { |
| 5394 | return entryList; |
| 5395 | } |
| 5396 | if (input[position.position] !== 13 || input[position.position + 1] !== 10) { |
| 5397 | return "failure"; |
| 5398 | } |
| 5399 | position.position += 2; |
| 5400 | const result = parseMultipartFormDataHeaders(input, position); |
| 5401 | if (result === "failure") { |
| 5402 | return "failure"; |
| 5403 | } |
| 5404 | let { name, filename, contentType, encoding } = result; |
| 5405 | position.position += 2; |
| 5406 | let body; |
| 5407 | { |
| 5408 | const boundaryIndex = input.indexOf(boundary.subarray(2), position.position); |
| 5409 | if (boundaryIndex === -1) { |
| 5410 | return "failure"; |
| 5411 | } |
| 5412 | body = input.subarray(position.position, boundaryIndex - 4); |
| 5413 | position.position += body.length; |
| 5414 | if (encoding === "base64") { |
| 5415 | body = Buffer.from(body.toString(), "base64"); |
| 5416 | } |
| 5417 | } |
| 5418 | if (input[position.position] !== 13 || input[position.position + 1] !== 10) { |
no test coverage detected