From d01474532b11014019d4d5a1197a8f8f7d683c0b Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sun, 7 Aug 2011 18:42:51 +0000 Subject: Don't allow newlines in the connection view input fields. Fixes issue #1008. --- Source/SPConnectionController.m | 12 ++++++++++++ Source/SPConnectionControllerDelegate.m | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'Source') diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index a5021206..937cb521 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -59,6 +59,7 @@ static NSString *SPExportFavoritesFilename = @"SequelProFavorites.plist"; - (NSNumber *)_createNewFavoriteID; - (SPTreeNode *)_favoriteNodeForFavoriteID:(NSInteger)favoriteID; +- (NSString *)_stripInvalidCharactersFromString:(NSString *)subject; - (void)_updateFavoritePasswordsFromField:(NSControl *)control; @@ -1395,6 +1396,17 @@ static NSComparisonResult compareFavoritesUsingKey(id favorite1, id favorite2, v return favoriteNode; } +/** + * Strips any invalid characters form the supplied string. Invalid is defined as any characters that should + * not be allowed to be enetered on the connection screen. + */ +- (NSString *)_stripInvalidCharactersFromString:(NSString *)subject +{ + NSString *result = [subject stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + return [result stringByReplacingOccurrencesOfString:@"\n" withString:@""]; +} + /** * Check all fields used in the keychain names against the old values for that * favorite, and update the keychain names to match if necessary. diff --git a/Source/SPConnectionControllerDelegate.m b/Source/SPConnectionControllerDelegate.m index 63f58ace..7d461233 100644 --- a/Source/SPConnectionControllerDelegate.m +++ b/Source/SPConnectionControllerDelegate.m @@ -44,6 +44,8 @@ static NSString *SPDatabaseImage = @"database-small"; - (void)_reloadFavoritesViewData; - (void)_updateFavoritePasswordsFromField:(NSControl *)control; +- (NSString *)_stripInvalidCharactersFromString:(NSString *)subject; + @end @implementation SPConnectionController (SPConnectionControllerDelegate) @@ -274,7 +276,9 @@ static NSString *SPDatabaseImage = @"database-small"; - (void)controlTextDidChange:(NSNotification *)notification { id field = [notification object]; - + + [field setStringValue:[self _stripInvalidCharactersFromString:[field stringValue]]]; + if (((field == standardNameField) || (field == socketNameField) || (field == sshNameField)) && [self selectedFavoriteNode]) { favoriteNameFieldWasTouched = YES; -- cgit v1.2.3