Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

[MM-13147] Fix for file_upload crash when mimeTypesSuffix is not present #2074

Merged
merged 6 commits into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions utils/file_utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,25 @@ export function getFileTypeFromMime(mimetype) {
const mimeTypeSplitBySlash = mimetype.split('/');
const mimeTypePrefix = mimeTypeSplitBySlash[0];
const mimeTypeSuffix = mimeTypeSplitBySlash[1];

if (mimeTypePrefix === 'video') {
return 'video';
} else if (mimeTypePrefix === 'audio') {
return 'audio';
} else if (mimeTypePrefix === 'image') {
return 'image';
} else if (mimeTypeSuffix === 'pdf') {
return 'pdf';
} else if (mimeTypeSuffix.includes('vnd.ms-excel') || mimeTypeSuffix.includes('spreadsheetml') || mimeTypeSuffix.includes('vnd.sun.xml.calc') || mimeTypeSuffix.includes('opendocument.spreadsheet')) {
return 'spreadsheet';
} else if (mimeTypeSuffix.includes('vnd.ms-powerpoint') || mimeTypeSuffix.includes('presentationml') || mimeTypeSuffix.includes('vnd.sun.xml.impress') || mimeTypeSuffix.includes('opendocument.presentation')) {
return 'presentation';
} else if ((mimeTypeSuffix === 'msword') || mimeTypeSuffix.includes('vnd.ms-word') || mimeTypeSuffix.includes('officedocument.wordprocessingml') || mimeTypeSuffix.includes('application/x-mswrite')) {
return 'word';
}

if(mimeTypeSuffix) {
sudheerDev marked this conversation as resolved.
Show resolved Hide resolved
if (mimeTypeSuffix === 'pdf') {
return 'pdf';
sudheerDev marked this conversation as resolved.
Show resolved Hide resolved
} else if (mimeTypeSuffix.includes('vnd.ms-excel') || mimeTypeSuffix.includes('spreadsheetml') || mimeTypeSuffix.includes('vnd.sun.xml.calc') || mimeTypeSuffix.includes('opendocument.spreadsheet')) {
return 'spreadsheet';
sudheerDev marked this conversation as resolved.
Show resolved Hide resolved
} else if (mimeTypeSuffix.includes('vnd.ms-powerpoint') || mimeTypeSuffix.includes('presentationml') || mimeTypeSuffix.includes('vnd.sun.xml.impress') || mimeTypeSuffix.includes('opendocument.presentation')) {
return 'presentation';
sudheerDev marked this conversation as resolved.
Show resolved Hide resolved
} else if ((mimeTypeSuffix === 'msword') || mimeTypeSuffix.includes('vnd.ms-word') || mimeTypeSuffix.includes('officedocument.wordprocessingml') || mimeTypeSuffix.includes('application/x-mswrite')) {
return 'word';
sudheerDev marked this conversation as resolved.
Show resolved Hide resolved
}
}

return 'other';
Expand Down
4 changes: 4 additions & 0 deletions utils/file_utils.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ describe('FileUtils.canUploadFiles', () => {
it('mime type for unknown file format', () => {
assert.equal(getFileTypeFromMime('application/unknownFormat'), 'other');
});

it('mime type for no suffix', () => {
assert.equal(getFileTypeFromMime('asdasd'), 'other');
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

});
});

Expand Down