Skip to content

Commit

Permalink
Don't encode URIs but check if it's a valid URI
Browse files Browse the repository at this point in the history
  • Loading branch information
julienXX committed May 13, 2017
1 parent aa2b032 commit 94738f8
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions Terminal Notifier/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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
Expand Down

0 comments on commit 94738f8

Please sign in to comment.