Percent escape strings before creating URLs

URLWithString will return nil if the string contains invalid URL
characters (such as spaces). Percent escape the string before attempting
to create an NSURL using it.
This commit is contained in:
James Hurst
2014-08-15 22:15:47 -04:00
parent cb46d54705
commit 4f33840b18

View File

@@ -616,10 +616,10 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
- (void)openURL:(id)sender { - (void)openURL:(id)sender {
KPKEntry *selectedEntry = [self _clickedOrSelectedEntry]; KPKEntry *selectedEntry = [self _clickedOrSelectedEntry];
if(selectedEntry && [selectedEntry.url length] > 0) { if(selectedEntry && [selectedEntry.url length] > 0) {
NSURL *webURL = [NSURL URLWithString:selectedEntry.url]; NSURL *webURL = [NSURL URLWithString:[selectedEntry.url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *scheme = [webURL scheme]; NSString *scheme = [webURL scheme];
if(!scheme) { if(!scheme) {
webURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", selectedEntry.url]]; webURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", [selectedEntry.url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
} }
[[NSWorkspace sharedWorkspace] openURL:webURL]; [[NSWorkspace sharedWorkspace] openURL:webURL];
/* Add custom browser support */ /* Add custom browser support */