From 2bbcd092bfeb7de5bb633fea05e6aaed9412c949 Mon Sep 17 00:00:00 2001 From: Mat Sz Date: Tue, 19 Dec 2023 15:04:20 +0100 Subject: [PATCH] fix issues with Content-Type values containing commas; #13 --- __tests__/parse.test.ts | 19 +++++++++++++++++++ src/parser.ts | 4 ---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/__tests__/parse.test.ts b/__tests__/parse.test.ts index 6581876..155dc2f 100644 --- a/__tests__/parse.test.ts +++ b/__tests__/parse.test.ts @@ -485,6 +485,25 @@ describe('parse', () => { ], }); }); + + it('should parse Content-Type values containing commas in quoted parameters', () => { + const output = parse( + `Content-Type: application/pdf; name="Hulick, Sam_AFPS Fee.pdf"\n\nABCDEF` + ); + expect(output).toMatchObject({ + contentType: { + type: 'application/pdf', + encoding: undefined, + parameters: { + name: 'Hulick, Sam_AFPS Fee.pdf', + }, + }, + body: 'ABCDEF', + headers: { + 'Content-Type': 'application/pdf; name="Hulick, Sam_AFPS Fee.pdf"', + }, + }); + }); }); describe('parseContentType', () => { diff --git a/src/parser.ts b/src/parser.ts index d1bc020..3906565 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -37,10 +37,6 @@ const MAX_DEPTH = 99; export function parseHeaderValue( value: string ): { firstValue: string; parameters: Headers } | undefined { - if (value.includes(',')) { - return undefined; - } - const split = value.split(';').map(s => s.trim()); const parameters: any = {};