Skip to content

Commit ba5bd72

Browse files
committed
return indices when CRLF is encountered
1 parent 8fdda19 commit ba5bd72

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/Multipart.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,29 +272,28 @@ export class Multipart implements Part {
272272
* @param data Multipart body bytes
273273
* @param boundary The multipart boundary bytes
274274
* @param [start] The index to start the search at (i.e. the number of bytes to skip/ignore at the beginning of the byte array). Defaults to 0.
275+
* @returns The start and end index of the boundary delimiter, or `null` if no boundary delimiter can be found
275276
* @internal
276277
*/
277278
private static findBoundaryBounds(data: Uint8Array, boundary: Uint8Array, start = 0): [number, number] | null {
278279
if (start >= data.length) return null;
279280
const boundaryStartIndex = Multipart.findSequenceIndex(data, Multipart.combineArrays([Multipart.CRLF, Multipart.DOUBLE_DASH, boundary]), start);
280281
if (boundaryStartIndex === -1) return null;
281-
// ignore any linear whitespace
282282
let currentEndOfBoundaryIndex = boundaryStartIndex + boundary.length + 4;
283283
while (currentEndOfBoundaryIndex < data.length) {
284284
const byte = data[currentEndOfBoundaryIndex];
285-
if (byte === Multipart.CR) break;
286-
if (byte === Multipart.LF) return null;
285+
if (byte === Multipart.CR && data[currentEndOfBoundaryIndex + 1] === Multipart.LF)
286+
return [boundaryStartIndex, currentEndOfBoundaryIndex + 2];
287287
if (byte === Multipart.SP || byte === 0x09) {
288288
currentEndOfBoundaryIndex++;
289289
continue;
290290
}
291-
// encountered non-linear whitespace after boundary and before any CR or LF
291+
// encountered non-linear whitespace after boundary and before any CRLF
292292
// meaning the boundary could not be terminated, therefore continue search for boundary
293293
return Multipart.findBoundaryBounds(data, boundary, boundaryStartIndex + 2);
294294
}
295-
if (data[currentEndOfBoundaryIndex + 1] !== Multipart.LF) return null;
296295

297-
return [boundaryStartIndex, currentEndOfBoundaryIndex + 2];
296+
return null;
298297
}
299298

300299
/**

0 commit comments

Comments
 (0)