Skip to content

Commit

Permalink
fix issues with Content-Type values containing commas; #13
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-sz committed Dec 19, 2023
1 parent 955ee36 commit 2bbcd09
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 19 additions & 0 deletions __tests__/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 0 additions & 4 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down

0 comments on commit 2bbcd09

Please sign in to comment.