Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(utils): allow for Unicode characters in Content-Disposition
Elian Doran5e0fb0e4af94
diff --git a/spec/utils.spec.ts b/spec/utils.spec.tsindex 055115bc72..c289e199fa 100644--- a/spec/utils.spec.ts+++ b/spec/utils.spec.ts@@ -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", () => {diff --git a/src/utils.ts b/src/utils.tsindex 80436e97b5..2a5a438d53 100644--- a/src/utils.ts+++ b/src/utils.ts@@ -9,5 +9,5 @@ export const setAcceptRangesHeader = setHeader.bind(null, "Accept-Ranges", "byteexport 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");