Fixed non-expanding of URLs on open

This commit is contained in:
michael starke
2015-01-08 13:35:05 +01:00
parent eb1bbc08a5
commit 9c364f3739

View File

@@ -645,22 +645,26 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
- (void)openURL:(id)sender { - (void)openURL:(id)sender {
KPKEntry *selectedEntry = [[self currentTargetNode] asEntry]; KPKEntry *selectedEntry = [[self currentTargetNode] asEntry];
if(selectedEntry && [selectedEntry.url length] > 0) { NSString *expandedURL = [selectedEntry.url finalValueForEntry:selectedEntry];
NSURL *webURL = [NSURL URLWithString:[selectedEntry.url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; if(expandedURL.length > 0) {
NSURL *webURL = [NSURL URLWithString:[expandedURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *scheme = [webURL scheme]; NSString *scheme = [webURL scheme];
if(!scheme) { if(!scheme) {
webURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", [selectedEntry.url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; webURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", [expandedURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
} }
NSString *browserBundleID = [[NSUserDefaults standardUserDefaults] objectForKey:kMPSettingsKeyBrowserBundleId]; NSString *browserBundleID = [[NSUserDefaults standardUserDefaults] objectForKey:kMPSettingsKeyBrowserBundleId];
BOOL launched = NO; BOOL openedURL = NO;
if (browserBundleID) { if(browserBundleID) {
launched = [[NSWorkspace sharedWorkspace] openURLs:@[webURL] withAppBundleIdentifier:browserBundleID options:NSWorkspaceLaunchAsync additionalEventParamDescriptor:nil launchIdentifiers:NULL]; openedURL = [[NSWorkspace sharedWorkspace] openURLs:@[webURL] withAppBundleIdentifier:browserBundleID options:NSWorkspaceLaunchAsync additionalEventParamDescriptor:nil launchIdentifiers:NULL];
} }
if (!launched) { if(!openedURL) {
[[NSWorkspace sharedWorkspace] openURL:webURL]; openedURL = [[NSWorkspace sharedWorkspace] openURL:webURL];
}
if(!openedURL) {
NSLog(@"Unable to open URL %@", webURL);
} }
} }
} }