Fix attachment extension vnd (#1628)

* allow openoffice document extension and don't use

* allow opendocument to be shared with the extension rather than mimetype

Fixes #1593

* allow message without padding

* add test for odt files
This commit is contained in:
Audric Ackermann 2021-05-13 13:32:52 +10:00 committed by GitHub
parent 3d9fbd9153
commit 12d40aa94e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 6 deletions

View File

@ -353,8 +353,6 @@ window.clipboard = clipboard;
window.seedNodeList = JSON.parse(config.seedNodeList);
const { OnionPaths } = require('./ts/session/onions');
const { locale: localFromEnv } = config;
window.i18n = i18n.setup(localFromEnv, localeMessages);
@ -375,8 +373,6 @@ window.moment.updateLocale(localeSetForMoment, {
},
});
window.OnionPaths = OnionPaths;
window.libsession = require('./ts/session');
window.models = require('./ts/models');

View File

@ -19,7 +19,8 @@ export function removeMessagePadding(paddedData: ArrayBuffer): ArrayBuffer {
plaintext.set(paddedPlaintext.subarray(0, i));
return plaintext.buffer;
} else if (paddedPlaintext[i] !== PADDING_BYTE) {
throw new Error('Invalid padding');
window.log.warn('got a message without padding... Letting it through for now');
return paddedPlaintext;
}
}

View File

@ -27,6 +27,15 @@ describe('Attachment', () => {
};
assert.strictEqual(Attachment.getFileExtension(input), 'mov');
});
it('should return file extension for application files', () => {
const input: Attachment.AttachmentType = {
fileName: 'funny-cat.odt',
url: 'funny-cat.odt',
contentType: MIME.ODT,
};
assert.strictEqual(Attachment.getFileExtension(input), 'odt');
});
});
describe('getSuggestedFilename', () => {

View File

@ -361,7 +361,12 @@ export const getSuggestedFilenameSending = ({
export const getFileExtension = (attachment: AttachmentType): string | undefined => {
// we override textplain to the extension of the file
if (!attachment.contentType || attachment.contentType === 'text/plain') {
// for contenttype starting with application, the mimetype is probably wrong so just use the extension of the file instead
if (
!attachment.contentType ||
attachment.contentType === 'text/plain' ||
attachment.contentType.startsWith('application')
) {
if (attachment.fileName?.length) {
const dotLastIndex = attachment.fileName.lastIndexOf('.');
if (dotLastIndex !== -1) {

View File

@ -14,6 +14,7 @@ export const IMAGE_WEBP = 'image/webp' as MIMEType;
export const IMAGE_PNG = 'image/png' as MIMEType;
export const VIDEO_MP4 = 'video/mp4' as MIMEType;
export const VIDEO_QUICKTIME = 'video/quicktime' as MIMEType;
export const ODT = 'application/vnd.oasis.opendocument.spreadsheet' as MIMEType;
export const isJPEG = (value: MIMEType): boolean => value === 'image/jpeg';
export const isImage = (value: MIMEType): boolean =>