Skip to content

Commit

Permalink
don't crash when url is not valid #196
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérôme Lebel committed Feb 13, 2015
1 parent 5c62e0c commit 945ce51
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ Please send me a [pull request](https://github.com/jeromelebel/MongoHub-Mac/pull
- Dropping support for 32bits
- Don't open a contextual menu if a sheet is opened [issue #183](https://github.com/jeromelebel/MongoHub-Mac/issues/183)
- Crash fixed to parse wrong regexp in a json [issue #191](https://github.com/jeromelebel/MongoHub-Mac/issues/191)
- Documents are copied inside an array (using the pasteboard) [issue #195](https://github.com/jeromelebel/MongoHub-Mac/issues/195)
- Fix for a crash when the server is not valid [issue #196](https://github.com/jeromelebel/MongoHub-Mac/issues/196)

**3.1 Beta**

- Documents are copied inside an array (using the pasteboard) [issue #195](https://github.com/jeromelebel/MongoHub-Mac/issues/195)
- Fix for a crash when the server is not valid [issue #196](https://github.com/jeromelebel/MongoHub-Mac/issues/196)

## History

Expand Down
7 changes: 5 additions & 2 deletions Resources/MHConnectionEditorWindow.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="14A389" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6254" systemVersion="14C109" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6250"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6254"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MHConnectionEditorWindowController">
Expand Down Expand Up @@ -466,6 +466,7 @@ Gw
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<outlet property="delegate" destination="-2" id="wSx-cc-8J6"/>
<outlet property="nextKeyView" destination="rqH-1A-H0s" id="6Jf-a8-19w"/>
</connections>
</textField>
Expand Down Expand Up @@ -516,6 +517,7 @@ Gw
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<outlet property="delegate" destination="-2" id="Q3a-H5-SLp"/>
<outlet property="nextKeyView" destination="79" id="Lnq-j1-4Qg"/>
</connections>
</textField>
Expand All @@ -524,6 +526,7 @@ Gw
</tabViewItem>
</tabViewItems>
<connections>
<outlet property="delegate" destination="-2" id="iD1-tK-Suq"/>
<outlet property="nextKeyView" destination="e3c-6q-I5k" id="hB5-z5-RfQ"/>
</connections>
</tabView>
Expand Down
18 changes: 18 additions & 0 deletions Sources/ConnectionControllers/MHConnectionEditorWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,16 @@ - (IBAction)addSaveAction:(id)sender
self.editedConnectionStore.sshPassword = self.sshPasswordTextField.stringValue;
self.editedConnectionStore.sshKeyFileName = self.sshKeyfileTextField.stringValue;
self.editedConnectionStore.defaultReadMode = preferenceReadModeFromTag(self.defaultReadModePopUpButton.selectedTag);

NSString *urlString;
MODClient *client;
urlString = [self.editedConnectionStore stringURLWithSSHMapping:nil];
client = [MODClient clientWihtURLString:urlString];
if (client == nil) {
NSBeginAlertSheet(@"Error", @"OK", nil, nil, self.window, nil, nil, nil, nil, @"Invalid URL %@", urlString);
return;
}

if (self.newConnection) {
[self.connectionsArrayController addObject:self.editedConnectionStore];
}
Expand Down Expand Up @@ -500,6 +510,14 @@ - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
} else {
self.adminPasswordTextField.stringValue = @"";
}
} else if (control == self.replicaSetServersTextField) {
if ([self.replicaSetServersTextField.stringValue hasPrefix:MONGODB_SCHEME]) {
self.replicaSetServersTextField.stringValue = [self.replicaSetServersTextField.stringValue substringFromIndex:MONGODB_SCHEME.length];
}
} else if (control == self.shardedClusterServersTextField) {
if ([self.shardedClusterServersTextField.stringValue hasPrefix:MONGODB_SCHEME]) {
self.shardedClusterServersTextField.stringValue = [self.shardedClusterServersTextField.stringValue substringFromIndex:MONGODB_SCHEME.length];
}
}
return YES;
}
Expand Down
20 changes: 12 additions & 8 deletions Sources/ConnectionWindow/MHConnectionWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,19 @@ - (void)connectToServer
urlString = [self.connectionStore stringURLWithSSHMapping:nil];
[self.delegate connectionWindowControllerLogMessage:urlString domain:[NSString stringWithFormat:@"%@.url", self.connectionStore.alias] level:@"debug"];
self.client = [MODClient clientWihtURLString:urlString];
self.client.sshMapping = self.sshBindedPortMapping;
if (self.connectionStore.useSSL) {
self.client.sslOptions = [[[MODSSLOptions alloc] initWithPemFileName:nil pemPassword:nil caFileName:nil caDirectory:nil crlFileName:nil weakCertificate:self.connectionStore.weakCertificate.boolValue] autorelease];
if (self.client == nil) {
NSBeginAlertSheet(@"Error", @"OK", nil, nil, self.window, nil, nil, nil, nil, @"Invalid URL %@", urlString);
} else {
self.client.sshMapping = self.sshBindedPortMapping;
if (self.connectionStore.useSSL) {
self.client.sslOptions = [[[MODSSLOptions alloc] initWithPemFileName:nil pemPassword:nil caFileName:nil caDirectory:nil crlFileName:nil weakCertificate:self.connectionStore.weakCertificate.boolValue] autorelease];
}
self.client.readPreferences = [MODReadPreferences readPreferencesWithReadMode:self.connectionStore.defaultReadMode];
[self.loaderIndicator stopAnimation:nil];

self.clientItem = [[[MHClientItem alloc] initWithClient:self.client] autorelease];
[self showServerStatus:nil];
}
self.client.readPreferences = [MODReadPreferences readPreferencesWithReadMode:self.connectionStore.defaultReadMode];
[self.loaderIndicator stopAnimation:nil];

self.clientItem = [[[MHClientItem alloc] initWithClient:self.client] autorelease];
[self showServerStatus:nil];
}
}

Expand Down
1 change: 1 addition & 0 deletions Sources/Model/MHConnectionStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "MHPreferenceWindowController.h"

#define DEFAULT_MONGO_IP @"127.0.0.1"
#define MONGODB_SCHEME @"mongodb://"

@interface MHConnectionStore : NSManagedObject
{
Expand Down
1 change: 0 additions & 1 deletion Sources/Model/MHConnectionStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#define QUERY_HISTORY_KEY @"query_history"
#define SORTED_TITLE_KEY @"sorted_titles"
#define QUERY_KEY @"queries"
#define MONGODB_SCHEME @"mongodb://"

@implementation MHConnectionStore

Expand Down

0 comments on commit 945ce51

Please sign in to comment.