Skip to content

Commit

Permalink
fix(utils): allow for Unicode characters in Content-Disposition
Browse files Browse the repository at this point in the history
  • Loading branch information
eliandoran committed Dec 11, 2024
1 parent 46ee587 commit 5e0fb0e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions spec/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ describe("utils tests", () => {
describe("setContentDispositionHeader tests", () => {
it("sets Content-Disposition header with specified value", () => {
const fileName = "file.txt";
const value = `attachment; filename="${fileName}"`;
const value = `attachment; filename*=utf-8''${fileName}`;
setContentDispositionHeader(fileName, res);
expect((res.setHeader as SinonStub).calledOnceWith("Content-Disposition", value));
expect((res.setHeader as SinonStub).calledOnceWith("Content-Disposition", value)).to.be.true;
});
it("sets Content-Disposition header with specified unicode", () => {
const fileName = "file.txt";
const value = `attachment; filename*=utf-8''${encodeURIComponent(fileName)}`;
setContentDispositionHeader(fileName, res);
expect((res.setHeader as SinonStub).calledOnceWith("Content-Disposition", value)).to.be.true;
});
});
describe("setCacheControlHeaderNoCache tests", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const setAcceptRangesHeader = setHeader.bind(null, "Accept-Ranges", "byte
export const setContentRangeHeader = (range: Range | null, size: number, res: Response) =>
setHeader("Content-Range", `bytes ${range ? `${range.start}-${range.end}` : "*"}/${size}`, res);
export const setContentDispositionHeader = (fileName: string, res: Response) =>
setHeader("Content-Disposition", `attachment; filename="${fileName}"`, res);
setHeader("Content-Disposition", `attachment; filename*=utf-8''${encodeURIComponent(fileName)}`, res);
export const setCacheControlHeaderNoCache = setHeader.bind(null, "Cache-Control", "no-cache");

0 comments on commit 5e0fb0e

Please sign in to comment.