Skip to content

Commit f37ff96

Browse files
committed
The export code caused an exception when no database was selected but the filename contained the database token (fixes #2145)
1 parent b7b9b15 commit f37ff96

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

Source/SPExportFilenameUtilities.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,15 @@ - (NSString *)expandCustomFilenameFormatUsingTableName:(NSString *)table
346346
NSString *tokenContent = [filenamePart tokenContent];
347347

348348
if ([tokenContent isEqualToString:NSLocalizedString(@"host", @"export filename host token")]) {
349-
[string appendString:[tableDocumentInstance host]];
349+
[string appendStringOrNil:[tableDocumentInstance host]];
350350

351351
}
352352
else if ([tokenContent isEqualToString:NSLocalizedString(@"database", @"export filename database token")]) {
353-
[string appendString:[tableDocumentInstance database]];
353+
[string appendStringOrNil:[tableDocumentInstance database]];
354354

355355
}
356356
else if ([tokenContent isEqualToString:NSLocalizedString(@"table", @"table")]) {
357-
[string appendString:(table) ? table : @""];
357+
[string appendStringOrNil:table];
358358
}
359359
else if ([tokenContent isEqualToString:NSLocalizedString(@"date", @"export filename date token")]) {
360360
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
@@ -380,7 +380,7 @@ - (NSString *)expandCustomFilenameFormatUsingTableName:(NSString *)table
380380
[string appendString:[dateFormatter stringFromDate:[NSDate date]]];
381381
}
382382
else if ([tokenContent isEqualToString:NSLocalizedString(@"favorite", @"export filename favorite name token")]) {
383-
[string appendString:[tableDocumentInstance name]];
383+
[string appendStringOrNil:[tableDocumentInstance name]];
384384
}
385385
}
386386
else {

Source/SPNarrowDownCompletion.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ - (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(id)aCell rect:
441441
} else {
442442
if([[filtered objectAtIndex:rowIndex] objectForKey:@"list"]) {
443443
NSMutableString *tt = [NSMutableString string];
444-
[tt appendString:([[filtered objectAtIndex:rowIndex] objectForKey:@"type"]) ? [[filtered objectAtIndex:rowIndex] objectForKey:@"type"] : @""];
444+
[tt appendStringOrNil:[[filtered objectAtIndex:rowIndex] objectForKey:@"type"]];
445445
[tt appendString:@"\n"];
446446
[tt appendString:NSLocalizedString(@"Type Declaration:", @"type declaration header")];
447447
[tt appendString:@"\n"];

Source/SPStringAdditions.h

+14
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,17 @@ static inline id NSMutableAttributedStringAttributeAtIndex(NSMutableAttributedSt
101101
*/
102102
- (BOOL)nonConsecutivelySearchString:(NSString *)other matchingRanges:(NSArray **)submatches;
103103
@end
104+
105+
@interface NSMutableString (SPStringAdditions)
106+
/**
107+
* nil-safe variant of setString:
108+
* nil will be interpreted as @"" instead of throwing an exception
109+
*/
110+
- (void)setStringOrNil:(NSString *)aString;
111+
112+
/**
113+
* nil-safe variant of appendString:
114+
* nil will be interpreted as @"" instead of throwing an exception
115+
*/
116+
- (void)appendStringOrNil:(NSString *)aString;
117+
@end

Source/SPStringAdditions.m

+14
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,17 @@ static NSInteger _smallestOf(NSInteger a, NSInteger b, NSInteger c)
562562

563563
return min;
564564
}
565+
566+
@implementation NSMutableString (SPStringAdditions)
567+
568+
- (void)setStringOrNil:(NSString *)aString
569+
{
570+
[self setString:(aString? aString : @"")];
571+
}
572+
573+
- (void)appendStringOrNil:(NSString *)aString
574+
{
575+
[self appendString:(aString? aString : @"")];
576+
}
577+
578+
@end

0 commit comments

Comments
 (0)