Permalink
Browse files

The export code caused an exception when no database was selected but…

… the filename contained the database token (fixes #2145)
  • Loading branch information...
dmoagx committed Jun 16, 2015
1 parent b7b9b15 commit f37ff9634d285d8d8f197d80ed29171dc9258270
Showing with 33 additions and 5 deletions.
  1. +4 −4 Source/SPExportFilenameUtilities.m
  2. +1 −1 Source/SPNarrowDownCompletion.m
  3. +14 −0 Source/SPStringAdditions.h
  4. +14 −0 Source/SPStringAdditions.m
@@ -346,15 +346,15 @@ - (NSString *)expandCustomFilenameFormatUsingTableName:(NSString *)table
NSString *tokenContent = [filenamePart tokenContent];
if ([tokenContent isEqualToString:NSLocalizedString(@"host", @"export filename host token")]) {
[string appendString:[tableDocumentInstance host]];
[string appendStringOrNil:[tableDocumentInstance host]];
}
else if ([tokenContent isEqualToString:NSLocalizedString(@"database", @"export filename database token")]) {
[string appendString:[tableDocumentInstance database]];
[string appendStringOrNil:[tableDocumentInstance database]];
}
else if ([tokenContent isEqualToString:NSLocalizedString(@"table", @"table")]) {
[string appendString:(table) ? table : @""];
[string appendStringOrNil:table];
}
else if ([tokenContent isEqualToString:NSLocalizedString(@"date", @"export filename date token")]) {
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
@@ -380,7 +380,7 @@ - (NSString *)expandCustomFilenameFormatUsingTableName:(NSString *)table
[string appendString:[dateFormatter stringFromDate:[NSDate date]]];
}
else if ([tokenContent isEqualToString:NSLocalizedString(@"favorite", @"export filename favorite name token")]) {
[string appendString:[tableDocumentInstance name]];
[string appendStringOrNil:[tableDocumentInstance name]];
}
}
else {
@@ -441,7 +441,7 @@ - (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(id)aCell rect:
} else {
if([[filtered objectAtIndex:rowIndex] objectForKey:@"list"]) {
NSMutableString *tt = [NSMutableString string];
[tt appendString:([[filtered objectAtIndex:rowIndex] objectForKey:@"type"]) ? [[filtered objectAtIndex:rowIndex] objectForKey:@"type"] : @""];
[tt appendStringOrNil:[[filtered objectAtIndex:rowIndex] objectForKey:@"type"]];
[tt appendString:@"\n"];
[tt appendString:NSLocalizedString(@"Type Declaration:", @"type declaration header")];
[tt appendString:@"\n"];
View
@@ -101,3 +101,17 @@ static inline id NSMutableAttributedStringAttributeAtIndex(NSMutableAttributedSt
*/
- (BOOL)nonConsecutivelySearchString:(NSString *)other matchingRanges:(NSArray **)submatches;
@end
@interface NSMutableString (SPStringAdditions)
/**
* nil-safe variant of setString:
* nil will be interpreted as @"" instead of throwing an exception
*/
- (void)setStringOrNil:(NSString *)aString;
/**
* nil-safe variant of appendString:
* nil will be interpreted as @"" instead of throwing an exception
*/
- (void)appendStringOrNil:(NSString *)aString;
@end
View
@@ -562,3 +562,17 @@ static NSInteger _smallestOf(NSInteger a, NSInteger b, NSInteger c)
return min;
}
@implementation NSMutableString (SPStringAdditions)
- (void)setStringOrNil:(NSString *)aString
{
[self setString:(aString? aString : @"")];
}
- (void)appendStringOrNil:(NSString *)aString
{
[self appendString:(aString? aString : @"")];
}
@end

0 comments on commit f37ff96

Please sign in to comment.