diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPConnectionController.m | 37 | ||||
-rw-r--r-- | Source/TableDocument.m | 4 |
2 files changed, 20 insertions, 21 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index baef9691..6670c732 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -657,8 +657,8 @@ { NSString *thePassword, *theSSHPassword; NSNumber *favoriteid = [NSNumber numberWithInt:[[NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]] hash]]; - NSString *favoriteName = [[self name] length]?[self name]:[NSString stringWithFormat:@"%@@%@", [self user], [self host]]; - if (![[self name] length] && ![[self database] isEqualToString:@""]) + NSString *favoriteName = [[self name] length]?[self name]:[NSString stringWithFormat:@"%@@%@", ([self user] && [[self user] length])?[self user]:@"anonymous", [self host]]; + if (![[self name] length] && [self database] && ![[self database] isEqualToString:@""]) favoriteName = [NSString stringWithFormat:@"%@ %@", [self database], favoriteName]; // Ensure that host is not empty if this is a TCP/IP or SSH connection @@ -676,21 +676,20 @@ // Ensure that a socket connection is not inadvertently used if (![self checkHost]) return; - // Construct the favorite details - NSDictionary *newFavorite = [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithInt:[self type]], @"type", - favoriteName, @"name", - [self host], @"host", - [self socket], @"socket", - [self user], @"user", - [self port], @"port", - [self database], @"database", - [self sshHost], @"sshHost", - [self sshUser], @"sshUser", - [self sshPort], @"sshPort", - favoriteid, @"id", - nil]; - + // Construct the favorite details - cannot use only dictionaryWithObjectsAndKeys for possible nil values. + NSMutableDictionary *newFavorite = [NSMutableDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithInt:[self type]], @"type", + favoriteName, @"name", + [self host], @"host", + favoriteid, @"id", + nil]; + if ([self socket]) [newFavorite setObject:[self socket] forKey:@"socket"]; + if ([self user]) [newFavorite setObject:[self user] forKey:@"user"]; + if ([self port]) [newFavorite setObject:[self port] forKey:@"port"]; + if ([self database]) [newFavorite setObject:[self database] forKey:@"database"]; + if ([self sshHost]) [newFavorite setObject:[self sshHost] forKey:@"sshHost"]; + if ([self sshUser]) [newFavorite setObject:[self sshUser] forKey:@"sshUser"]; + if ([self sshPort]) [newFavorite setObject:[self sshPort] forKey:@"sshPort"]; // Add the new favorite to the user defaults array NSMutableArray *currentFavorites; @@ -708,7 +707,7 @@ if (mySQLConnection && connectionKeychainItemName) { thePassword = [keychain getPasswordForName:connectionKeychainItemName account:connectionKeychainItemAccount]; } - if (![thePassword isEqualToString:@""]) { + if (thePassword && ![thePassword isEqualToString:@""]) { [keychain addPassword:thePassword forName:[keychain nameForFavoriteName:favoriteName id:[NSString stringWithFormat:@"%i", [favoriteid intValue]]] account:[keychain accountForUser:[self user] host:[self host] database:[self database]]]; @@ -719,7 +718,7 @@ if (mySQLConnection && connectionSSHKeychainItemName) { theSSHPassword = [keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount]; } - if (![theSSHPassword isEqualToString:@""]) { + if (theSSHPassword && ![theSSHPassword isEqualToString:@""]) { [keychain addPassword:theSSHPassword forName:[keychain nameForSSHForFavoriteName:favoriteName id:[NSString stringWithFormat:@"%i", [favoriteid intValue]]] account:[keychain accountForSSHUser:[self sshUser] sshHost:[self sshHost]]]; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 1063070b..1057be90 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -1445,9 +1445,9 @@ return [connectionController name]; } if ([connectionController type] == SP_CONNECTION_SOCKET) { - return [NSString stringWithFormat:@"%@@localhost", [connectionController user]?[connectionController user]:@""]; + return [NSString stringWithFormat:@"%@@localhost", ([connectionController user] && [[connectionController user] length])?[connectionController user]:@"anonymous"]; } - return [NSString stringWithFormat:@"%@@%@", [connectionController user]?[connectionController user]:@"", [connectionController host]?[connectionController host]:@""]; + return [NSString stringWithFormat:@"%@@%@", ([connectionController user] && [[connectionController user] length])?[connectionController user]:@"anonymous", [connectionController host]?[connectionController host]:@""]; } /** |