Permalink
Browse files

Encoding detection logic was fixed

  • Loading branch information...
1 parent 90999ca commit 68959bd141dd4141a0b6380268c3db674f4eb993 @rbsgn rbsgn committed with Feb 25, 2009
Showing with 11 additions and 2 deletions.
  1. +11 −2 ASIHTTPRequest.m
View
@@ -769,8 +769,17 @@ - (BOOL)readResponseHeadersReturningAuthenticationFailure
NSString *contentType = [[self responseHeaders] objectForKey:@"Content-Type"];
NSStringEncoding encoding = [self defaultResponseEncoding];
if (contentType) {
- NSArray *parts = [contentType componentsSeparatedByString:@"="];
- NSString *IANAEncoding = [parts objectAtIndex:[parts count]-1];
+
+ NSString *charsetSeparator = @"charset=";
+ NSScanner *charsetScanner = [NSScanner scannerWithString: contentType];
+ NSString *IANAEncoding = nil;
+
+ if ([charsetScanner scanUpToString: charsetSeparator intoString: NULL])
+ {
+ [charsetScanner setScanLocation: [charsetScanner scanLocation] + [charsetSeparator length]];
+ [charsetScanner scanUpToString: @";" intoString: &IANAEncoding];
+ }
+
if (IANAEncoding) {
CFStringEncoding cfEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)IANAEncoding);
if (cfEncoding != kCFStringEncodingInvalidId) {

0 comments on commit 68959bd

Please sign in to comment.