From 1464536b9f8c3448fc53d07b17e9614f6925b00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Iv=C3=A1n=20Vieitez=20Parra?= <3857362+corrideat@users.noreply.github.com> Date: Sat, 15 Apr 2023 11:15:34 +0200 Subject: [PATCH] Update boundary regex --- package.json | 4 ++-- src/parseMultipartMessage.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index d6ebaaf..3782817 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@exact-realty/multipart-parser", - "version": "1.0.0", - "description": "MIME multipart parser", + "version": "1.0.1", + "description": "TypeScript streaming parser for MIME multipart messages", "main": "dist/index.js", "module": "./dist/index.mjs", "exports": { diff --git a/src/parseMultipartMessage.ts b/src/parseMultipartMessage.ts index 3e9a5a6..eefe31c 100644 --- a/src/parseMultipartMessage.ts +++ b/src/parseMultipartMessage.ts @@ -30,11 +30,19 @@ const textEncoder = new TextEncoder(); const newline = textEncoder.encode('\r\n'); const LWSPchar = [0x09, 0x20]; +/* From RFC 2046 section 5.1.1 */ export const boundaryRegex = /^[0-9a-zA-Z'()+_,\-./:=? ]{0,69}[0-9a-zA-Z'()+_,\-./:=?]$/; +/* From RFC 2045 section 5.1 + tspecials := "(" / ")" / "<" / ">" / "@" / + "," / ";" / ":" / "\" / <"> + "/" / "[" / "]" / "?" / "=" + ; Must be in quoted-string, + ; to use within parameter values +*/ export const boundaryMatchRegex = - /;\s*boundary=(?:"([0-9a-zA-Z'()+_,\-./:=? ]{0,69}[0-9a-zA-Z'()+_,\-./:=?])"|([0-9a-zA-Z'()+_,\-./=?]{0,69}[0-9a-zA-Z'()+_,\-./=?]))/; + /;\s*boundary=(?:"([0-9a-zA-Z'()+_,\-./:=? ]{0,69}[0-9a-zA-Z'()+_,\-./:=?])"|([0-9a-zA-Z'+_\-.]{0,69}[0-9a-zA-Z'+_\-.]))/; export type TMultipartMessageIterator = AsyncGenerator<{ headers: Headers;