Skip to content

Commit d12e2d9

Browse files
pedrlaurent22
andcommitted
Desktop: Fixes #11759: Preserve attachment file extensions regardless of the mime type (#11852)
Co-authored-by: Laurent Cozic <laurent22@users.noreply.github.com>
1 parent 17e463b commit d12e2d9

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

packages/lib/shim-init-node.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const { shimInit } = require('./shim-init-node');
33
import shim from './shim';
44
import { setupDatabaseAndSynchronizer, supportDir } from './testing/test-utils';
5+
import { copyFile } from 'fs-extra';
56

67
describe('shim-init-node', () => {
78

@@ -10,10 +11,21 @@ describe('shim-init-node', () => {
1011
shimInit();
1112
});
1213

13-
test('should set mime the correct mime for a PDF file even if the extension is missing', async () => {
14+
test('should set the correct mime for a PDF file even if the extension is missing', async () => {
1415
const filePath = `${supportDir}/valid_pdf_without_ext`;
1516
const resource = await shim.createResourceFromPath(filePath);
1617

1718
expect(resource.mime).toBe('application/pdf');
1819
});
20+
21+
test('should preserve the file extension if one is provided regardless of the mime type', async () => {
22+
const originalFilePath = `${supportDir}/valid_pdf_without_ext`;
23+
const fileWithDifferentExtension = `${originalFilePath}.mscz`;
24+
await copyFile(originalFilePath, fileWithDifferentExtension);
25+
26+
const resource = await shim.createResourceFromPath(fileWithDifferentExtension);
27+
28+
expect(resource.file_extension).toBe('mscz');
29+
});
30+
1931
});

packages/lib/shim-init-node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ function shimInit(options: ShimInitOptions = null) {
344344
const detectedType = await fileTypeFromFile(filePath);
345345

346346
if (detectedType) {
347-
fileExt = detectedType.ext;
347+
fileExt = fileExt ? fileExt : detectedType.ext;
348348
resource.mime = detectedType.mime;
349349
} else {
350350
resource.mime = 'application/octet-stream';

0 commit comments

Comments
 (0)