mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-24 02:52:24 -08:00
fix(core): Account for non-ASCII chars in filename on binary data download (#7742)
https://n8nio.sentry.io/issues/4641538638
This commit is contained in:
parent
abe36691ab
commit
b4ebb1a28d
|
@ -41,8 +41,9 @@ export class BinaryDataController {
|
||||||
|
|
||||||
if (mimeType) res.setHeader('Content-Type', mimeType);
|
if (mimeType) res.setHeader('Content-Type', mimeType);
|
||||||
|
|
||||||
if (action === 'download') {
|
if (action === 'download' && fileName) {
|
||||||
res.setHeader('Content-Disposition', `attachment; filename="${fileName}"`);
|
const encodedFilename = encodeURIComponent(fileName);
|
||||||
|
res.setHeader('Content-Disposition', `attachment; filename="${encodedFilename}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.binaryDataService.getAsStream(binaryDataId);
|
return await this.binaryDataService.getAsStream(binaryDataId);
|
||||||
|
|
|
@ -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]', () => {
|
describe('should return 404 on file not found [filesystem]', () => {
|
||||||
test.each(['view', 'download'])('on request to %s', async (action) => {
|
test.each(['view', 'download'])('on request to %s', async (action) => {
|
||||||
binaryDataService.getAsStream.mockImplementation(throwFileNotFound);
|
binaryDataService.getAsStream.mockImplementation(throwFileNotFound);
|
||||||
|
|
Loading…
Reference in a new issue