From 94738f8ac9acec635704d5716267856707306857 Mon Sep 17 00:00:00 2001 From: Julien Blanchard Date: Sat, 13 May 2017 18:43:46 +0200 Subject: [PATCH] Don't encode URIs but check if it's a valid URI --- Terminal Notifier/AppDelegate.m | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/Terminal Notifier/AppDelegate.m b/Terminal Notifier/AppDelegate.m index 7826891..5b6beb4 100644 --- a/Terminal Notifier/AppDelegate.m +++ b/Terminal Notifier/AppDelegate.m @@ -205,17 +205,12 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification; if (options[@"reply"] || defaults[@"timeout"] || defaults[@"actions"] || defaults[@"execute"] || defaults[@"open"] || options[@"bundleID"]) options[@"waitForResponse"] = @YES; if (defaults[@"open"]) { - /* - * it may be better to use stringByAddingPercentEncodingWithAllowedCharacters instead of stringByAddingPercentEscapesUsingEncoding, - * but stringByAddingPercentEncodingWithAllowedCharacters is only available on OS X 10.9 or higher. - */ - NSString *encodedURL = [defaults[@"open"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL *url = [NSURL URLWithString:defaults[@"open"]]; - NSString *fragment = [url fragment]; - if (fragment) { - options[@"open"] = [self decodeFragmentInURL:encodedURL fragment:fragment]; - } else { - options[@"open"] = encodedURL; + if (url && url.scheme && url.host) { + options[@"open"] = defaults[@"open"]; + }else{ + printf("%s", "Error: You need to pass a valid URI to -open.\n"); + exit(1); } } @@ -240,20 +235,6 @@ - (NSImage*)getImageFromURL:(NSString *) url; return [[NSImage alloc] initWithContentsOfURL:imageURL]; } -/** - * Decode fragment identifier - * - * @see http://tools.ietf.org/html/rfc3986#section-2.1 - * @see http://en.wikipedia.org/wiki/URI_scheme - */ -- (NSString*)decodeFragmentInURL:(NSString *) encodedURL fragment:(NSString *) framgent -{ - NSString *beforeStr = [@"%23" stringByAppendingString:framgent]; - NSString *afterStr = [@"#" stringByAppendingString:framgent]; - NSString *decodedURL = [encodedURL stringByReplacingOccurrencesOfString:beforeStr withString:afterStr]; - return decodedURL; -} - - (void)deliverNotificationWithTitle:(NSString *)title subtitle:(NSString *)subtitle message:(NSString *)message