From 4f33840b184844379651e9e21c340b35b9d78c81 Mon Sep 17 00:00:00 2001 From: James Hurst Date: Fri, 15 Aug 2014 22:15:47 -0400 Subject: [PATCH] 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. --- MacPass/MPEntryViewController.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index a207f05c..e6b4652e 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -616,10 +616,10 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; - (void)openURL:(id)sender { KPKEntry *selectedEntry = [self _clickedOrSelectedEntry]; if(selectedEntry && [selectedEntry.url length] > 0) { - NSURL *webURL = [NSURL URLWithString:selectedEntry.url]; + NSURL *webURL = [NSURL URLWithString:[selectedEntry.url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSString *scheme = [webURL 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]; /* Add custom browser support */