Skip to content

Commit

Permalink
fix: resolve issues with empty space in header parameter values (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-sz committed May 12, 2024
1 parent 4f3b4b0 commit aa12685
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions __tests__/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,13 @@ describe('parseContentType', () => {
parameters: { name: 'prüfbericht.pdf' },
});
});

// Issue #17: https://github.com/mat-sz/letterparser/issues/17
it('should handle empty space correctly', () => {
expect(parseContentType('text/plain; charset = "utf-8"')).toMatchObject({
type: 'text/plain',
encoding: 'utf-8',
parameters: { charset: 'utf-8' },
});
});
});
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function parseHeaderValue(
continue;
}

let value = parameterSplit[1];
let value = parameterSplit[1].trim();
if (parameterSplit.length > 2) {
value = parameterSplit.slice(1).join('=');
}
Expand Down

0 comments on commit aa12685

Please sign in to comment.