Skip to content

Commit

Permalink
Fix crash when attempting to hash a nil url (closes pokebgh-201 , closes
Browse files Browse the repository at this point in the history
  • Loading branch information
pokeb committed Jun 4, 2011
1 parent 2851730 commit 5e35006
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Classes/ASIDownloadCache.m
Expand Up @@ -435,15 +435,19 @@ + (BOOL)serverAllowsResponseCachingForRequest:(ASIHTTPRequest *)request
return YES;
}


// Borrowed from: http://stackoverflow.com/questions/652300/using-md5-hash-on-a-string-in-cocoa
+ (NSString *)keyForURL:(NSURL *)url
{
NSString *urlString = [url absoluteString];
if ([urlString length] == 0) {
return nil;
}

// Strip trailing slashes so http://allseeing-i.com/ASIHTTPRequest/ is cached the same as http://allseeing-i.com/ASIHTTPRequest
if ([[urlString substringFromIndex:[urlString length]-1] isEqualToString:@"/"]) {
urlString = [urlString substringToIndex:[urlString length]-1];
}

// Borrowed from: http://stackoverflow.com/questions/652300/using-md5-hash-on-a-string-in-cocoa
const char *cStr = [urlString UTF8String];
unsigned char result[16];
CC_MD5(cStr, (CC_LONG)strlen(cStr), result);
Expand Down
2 changes: 1 addition & 1 deletion Classes/ASIHTTPRequest.m
Expand Up @@ -24,7 +24,7 @@
#import "ASIDataCompressor.h"

// Automatically set on build
NSString *ASIHTTPRequestVersion = @"v1.8.1-2 2011-06-04";
NSString *ASIHTTPRequestVersion = @"v1.8.1-4 2011-06-04";

static NSString *defaultUserAgent = nil;

Expand Down

0 comments on commit 5e35006

Please sign in to comment.