diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m index 916c70d30..53f33f172 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m @@ -284,6 +284,10 @@ NS_ASSUME_NONNULL_BEGIN actionBlock:^{ [DebugUIMessages testZalgoTextInThread:thread]; }], + [OWSTableItem itemWithTitle:@"Test Directional Filenames" + actionBlock:^{ + [DebugUIMessages testDirectionalFilenamesInThread:thread]; + }], ] mutableCopy]; if ([thread isKindOfClass:[TSContactThread class]]) { TSContactThread *contactThread = (TSContactThread *)thread; @@ -1684,6 +1688,43 @@ NS_ASSUME_NONNULL_BEGIN }]; } ++ (void)testDirectionalFilenamesInThread:(TSThread *)thread +{ + NSMutableArray *filenames = [@[ + @"a_test\u202Dabc.exe", + @"b_test\u202Eabc.exe", + @"c_testabc.exe", + ] mutableCopy]; + __block void (^sendUnsafeFile)(void); + sendUnsafeFile = ^{ + if (filenames.count < 1) { + return; + } + NSString *filename = filenames.lastObject; + [filenames removeLastObject]; + OWSMessageSender *messageSender = [Environment current].messageSender; + NSString *utiType = (NSString *)kUTTypeData; + const NSUInteger kDataLength = 32; + DataSource *_Nullable dataSource = + [DataSourceValue dataSourceWithData:[self createRandomNSDataOfSize:kDataLength] utiType:utiType]; + [dataSource setSourceFilename:filename]; + SignalAttachment *attachment = + [SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType imageQuality:TSImageQualityOriginal]; + + OWSAssert(attachment); + if ([attachment hasError]) { + DDLogError(@"attachment[%@]: %@", [attachment sourceFilename], [attachment errorName]); + [DDLog flushLog]; + } + OWSAssert(![attachment hasError]); + [ThreadUtil sendMessageWithAttachment:attachment inThread:thread messageSender:messageSender completion:nil]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + sendUnsafeFile(); + }); + }; +} + @end NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/attachments/SignalAttachment.swift b/SignalMessaging/attachments/SignalAttachment.swift index ee5e40e57..383510605 100644 --- a/SignalMessaging/attachments/SignalAttachment.swift +++ b/SignalMessaging/attachments/SignalAttachment.swift @@ -130,7 +130,7 @@ public class SignalAttachment: NSObject { @objc public var sourceFilename: String? { - return dataSource.sourceFilename?.filterStringForDisplay() + return dataSource.sourceFilename?.filterFilename() } @objc @@ -311,7 +311,7 @@ public class SignalAttachment: NSObject { @objc public var filenameOrDefault: String { if let filename = sourceFilename { - return filename.filterStringForDisplay() + return filename.filterFilename() } else { let kDefaultAttachmentName = "signal" @@ -335,7 +335,7 @@ public class SignalAttachment: NSObject { if let filename = sourceFilename { let fileExtension = (filename as NSString).pathExtension if fileExtension.count > 0 { - return fileExtension.filterStringForDisplay() + return fileExtension.filterFilename() } } if isOversizeText { diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachment.m b/SignalServiceKit/src/Messages/Attachments/TSAttachment.m index 17fc29139..43af0899d 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachment.m +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachment.m @@ -192,12 +192,12 @@ NSUInteger const TSAttachmentSchemaVersion = 4; - (nullable NSString *)sourceFilename { - return _sourceFilename.filterStringForDisplay; + return _sourceFilename.filterFilename; } - (NSString *)contentType { - return _contentType.filterStringForDisplay; + return _contentType.filterFilename; } @end diff --git a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m index fe60d0dfa..debd8e82d 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m @@ -529,6 +529,7 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec [builder setId:attachmentStream.serverId]; OWSAssert(attachmentStream.contentType.length > 0); [builder setContentType:attachmentStream.contentType]; + DDLogVerbose(@"%@ Sending attachment with filename: '%@'", self.logTag, filename); [builder setFileName:filename]; [builder setSize:attachmentStream.byteCount]; [builder setKey:attachmentStream.encryptionKey]; diff --git a/SignalServiceKit/src/Messages/OWSReadReceiptManager.m b/SignalServiceKit/src/Messages/OWSReadReceiptManager.m index 97dc644a8..60383569b 100644 --- a/SignalServiceKit/src/Messages/OWSReadReceiptManager.m +++ b/SignalServiceKit/src/Messages/OWSReadReceiptManager.m @@ -357,7 +357,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE ofClass:[TSOutgoingMessage class] withTransaction:transaction]; if (messages.count > 1) { - OWSFail(@"%@ More than one matching message with timestamp: %llu.", self.logTag, sentTimestamp); + DDLogError(@"%@ More than one matching message with timestamp: %llu.", self.logTag, sentTimestamp); } if (messages.count > 0) { // TODO: We might also need to "mark as read by recipient" any older messages diff --git a/SignalServiceKit/src/Util/DataSource.m b/SignalServiceKit/src/Util/DataSource.m index c32bd7a3a..e5602ade1 100755 --- a/SignalServiceKit/src/Util/DataSource.m +++ b/SignalServiceKit/src/Util/DataSource.m @@ -80,7 +80,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)setSourceFilename:(nullable NSString *)sourceFilename { - _sourceFilename = sourceFilename.filterStringForDisplay; + _sourceFilename = sourceFilename.filterFilename; } @end diff --git a/SignalServiceKit/src/Util/NSString+SSK.h b/SignalServiceKit/src/Util/NSString+SSK.h index f48cc8fc7..88ffba9df 100644 --- a/SignalServiceKit/src/Util/NSString+SSK.h +++ b/SignalServiceKit/src/Util/NSString+SSK.h @@ -10,6 +10,8 @@ NS_ASSUME_NONNULL_BEGIN - (NSString *)filterStringForDisplay; +- (NSString *)filterFilename; + - (BOOL)isValidE164; @end diff --git a/SignalServiceKit/src/Util/NSString+SSK.m b/SignalServiceKit/src/Util/NSString+SSK.m index 8e03d13ea..7eb4e3ac0 100644 --- a/SignalServiceKit/src/Util/NSString+SSK.m +++ b/SignalServiceKit/src/Util/NSString+SSK.m @@ -144,7 +144,7 @@ NS_ASSUME_NONNULL_BEGIN return [filteredForIndic copy]; } -+ (NSCharacterSet *)unsafeCharacterSet ++ (NSCharacterSet *)unsafeFilenameCharacterSet { static NSCharacterSet *characterSet; static dispatch_once_t onceToken; @@ -160,9 +160,9 @@ NS_ASSUME_NONNULL_BEGIN return characterSet; } -- (NSString *)filterUnsafeCharacters +- (NSString *)filterUnsafeFilenameCharacters { - NSCharacterSet *unsafeCharacterSet = [[self class] unsafeCharacterSet]; + NSCharacterSet *unsafeCharacterSet = [[self class] unsafeFilenameCharacterSet]; NSRange range = [self rangeOfCharacterFromSet:unsafeCharacterSet]; if (range.location == NSNotFound) { return self; @@ -184,7 +184,12 @@ NS_ASSUME_NONNULL_BEGIN - (NSString *)filterStringForDisplay { - return self.ows_stripped.filterForIndicScripts.filterForExcessiveDiacriticals.filterUnsafeCharacters; + return self.ows_stripped.filterForIndicScripts.filterForExcessiveDiacriticals; +} + +- (NSString *)filterFilename +{ + return self.ows_stripped.filterForIndicScripts.filterForExcessiveDiacriticals.filterUnsafeFilenameCharacters; } - (NSString *)filterForExcessiveDiacriticals