From 3e9fbb1bec502ee1780767c91262174d0b5910ac Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 8 May 2017 15:49:28 -0400 Subject: [PATCH] Prefer to deduce the MIME type from the file extension using lookup, not the UTI type. // FREEBIE --- src/Util/MIMETypeUtil.m | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Util/MIMETypeUtil.m b/src/Util/MIMETypeUtil.m index 7d12fdc4f..fa3c5a717 100644 --- a/src/Util/MIMETypeUtil.m +++ b/src/Util/MIMETypeUtil.m @@ -2568,11 +2568,16 @@ NSString *const OWSMimeTypeUnknownForTests = @"unknown/mimetype"; + (nullable NSString *)fileExtensionForMIMEType:(NSString *)mimeType { - // Try to deduce the file extension by converting to a UTI type. - NSString *_Nullable fileExtension = [self fileExtensionForMIMETypeViaUTIType:mimeType]; + // Try to deduce the file extension by using a lookup table. + // + // This should be more accurate than deducing the file extension by + // converting to a UTI type. For example, .m4a files will have a + // UTI type of kUTTypeMPEG4Audio which incorrectly yields the file + // extension .mp4 instead of .m4a. + NSString *_Nullable fileExtension = [self fileExtensionForMIMETypeViaLookup:mimeType]; if (!fileExtension) { - // Try to deduce the file extension by using a lookup table.. - fileExtension = [self fileExtensionForMIMETypeViaLookup:mimeType]; + // Try to deduce the file extension by converting to a UTI type. + fileExtension = [self fileExtensionForMIMETypeViaUTIType:mimeType]; } return fileExtension; }