Skip to content

Commit

Permalink
fix(core): Account for non-ASCII chars in filename on binary data dow…
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov authored Nov 17, 2023
1 parent abe3669 commit b4ebb1a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/cli/src/controllers/binaryData.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ export class BinaryDataController {

if (mimeType) res.setHeader('Content-Type', mimeType);

if (action === 'download') {
res.setHeader('Content-Disposition', `attachment; filename="${fileName}"`);
if (action === 'download' && fileName) {
const encodedFilename = encodeURIComponent(fileName);
res.setHeader('Content-Disposition', `attachment; filename="${encodedFilename}"`);
}

return await this.binaryDataService.getAsStream(binaryDataId);
Expand Down
20 changes: 20 additions & 0 deletions packages/cli/test/integration/binaryData.api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ describe('GET /binary-data', () => {
});
});

describe('should handle non-ASCII filename [filesystem]', () => {
test('on request to download', async () => {
const nonAsciiFileName = 'äöüß.png';

const res = await authOwnerAgent
.get('/binary-data')
.query({
id: fsBinaryDataId,
fileName: nonAsciiFileName,
mimeType,
action: 'download',
})
.expect(200);

expect(res.headers['content-disposition']).toBe(
`attachment; filename="${encodeURIComponent(nonAsciiFileName)}"`,
);
});
});

describe('should return 404 on file not found [filesystem]', () => {
test.each(['view', 'download'])('on request to %s', async (action) => {
binaryDataService.getAsStream.mockImplementation(throwFileNotFound);
Expand Down

0 comments on commit b4ebb1a

Please sign in to comment.