mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 19:12:27 +08:00
fix(utils): allow for Unicode characters in Content-Disposition
This commit is contained in:
parent
46ee587685
commit
5e0fb0e4af
@ -89,9 +89,15 @@ describe("utils tests", () => {
|
|||||||
describe("setContentDispositionHeader tests", () => {
|
describe("setContentDispositionHeader tests", () => {
|
||||||
it("sets Content-Disposition header with specified value", () => {
|
it("sets Content-Disposition header with specified value", () => {
|
||||||
const fileName = "file.txt";
|
const fileName = "file.txt";
|
||||||
const value = `attachment; filename="${fileName}"`;
|
const value = `attachment; filename*=utf-8''${fileName}`;
|
||||||
setContentDispositionHeader(fileName, res);
|
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", () => {
|
describe("setCacheControlHeaderNoCache tests", () => {
|
||||||
|
@ -9,5 +9,5 @@ export const setAcceptRangesHeader = setHeader.bind(null, "Accept-Ranges", "byte
|
|||||||
export const setContentRangeHeader = (range: Range | null, size: number, res: Response) =>
|
export const setContentRangeHeader = (range: Range | null, size: number, res: Response) =>
|
||||||
setHeader("Content-Range", `bytes ${range ? `${range.start}-${range.end}` : "*"}/${size}`, res);
|
setHeader("Content-Range", `bytes ${range ? `${range.start}-${range.end}` : "*"}/${size}`, res);
|
||||||
export const setContentDispositionHeader = (fileName: string, res: Response) =>
|
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");
|
export const setCacheControlHeaderNoCache = setHeader.bind(null, "Cache-Control", "no-cache");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user