Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

detect valid URLs

  • Loading branch information...
commit 527b8d52838454644c8a9a6041d4a49875e74a4c 1 parent cece295
@labria authored
Showing with 26 additions and 11 deletions.
  1. +25 −10 AppDelegate.m
  2. +1 −1  GrowlSender.m
View
35 AppDelegate.m
@@ -27,12 +27,20 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
if (evtDesc && (evtID == kAEReopenApplication || evtID == kAEOpenApplication) && [evtDesc eventClass] == kCoreEventClass) {
Clip * clip = [[Clip alloc] init];
[clip getData];
- BitLyParser * parser = [BitLyParser newWithURLFromString:[clip string_]];
- [parser getData];
- NSString * result = [parser parseXML];
- [clip setData:result];
+ NSString * url_string = [clip string_];
+ NSString * url_scheme = [[NSURL URLWithString:url_string] scheme];
+ if (url_scheme == nil) {
+ // It is not a url
+ [growl_ growlString:@"No valid URL provided"];
+ } else {
+ // It's a url
+ BitLyParser * parser = [BitLyParser newWithURLFromString:[clip string_]];
+ [parser getData];
+ NSString * result = [parser parseXML];
+ [growl_ growlString:result];
+ [clip_ setData:result];
+ }
- [growl_ growlString:result];
[NSApp terminate:self];
}
}
@@ -55,11 +63,18 @@ - (void)shortenURL:(NSPasteboard *)pboard
return;
}
- BitLyParser * parser = [BitLyParser newWithURLFromString:pboardString];
- [parser getData];
- NSString * result = [parser parseXML];
- [clip_ setData:result];
- [growl_ growlString:result];
+ NSString * url_scheme = [[NSURL URLWithString:pboardString] scheme];
+ if (url_scheme == nil) {
+ // It is not a url
+ [growl_ growlString:@"No valid URL provided"];
+ } else {
+ // It's a url
+ BitLyParser * parser = [BitLyParser newWithURLFromString:pboardString];
+ [parser getData];
+ NSString * result = [parser parseXML];
+ [clip_ setData:result];
+ [growl_ growlString:result];
+ }
[NSApp terminate:self];
}
View
2  GrowlSender.m
@@ -35,7 +35,7 @@ - (NSDictionary*) registrationDictionaryForGrowl
- (void)growlString:(NSString *) string
{
- [GrowlApplicationBridge notifyWithTitle: @"Bitly client"
+ [GrowlApplicationBridge notifyWithTitle: @"Bit.ly client"
description: string
notificationName:growlTestNotification
iconData:nil
Please sign in to comment.
Something went wrong with that request. Please try again.