Permalink
Browse files

Fix issue with new encoding parsing code

All tests now pass on Mac and iPhone
  • Loading branch information...
1 parent 931176e commit 2355f635b8e4ce46a2de040bf681478a9ea4d4ce @pokeb committed Feb 27, 2009
Showing with 104 additions and 191 deletions.
  1. +4 −0 ASIFormDataRequestTests.m
  2. +5 −2 ASIHTTPRequest.m
  3. +6 −6 ASIHTTPRequestTests.m
  4. +89 −183 asi-http-request.xcodeproj/project.pbxproj
@@ -25,7 +25,11 @@ - (void)testPostWithFileUpload
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
NSDate *d = [NSDate new];
+#if TARGET_OS_IPHONE
NSValue *v = [NSValue valueWithCGRect:CGRectMake(0, 0, 200, 200)];
+#else
+ NSValue *v = [NSValue valueWithRect:NSMakeRect(0, 0, 200, 200)];
+#endif
[request setPostValue:@"foo" forKey:@"post_var"];
[request setPostValue:d forKey:@"post_var2"];
[request setPostValue:v forKey:@"post_var3"];
View
@@ -593,11 +593,13 @@ - (void)resetDownloadProgress:(unsigned long long)value
- (void)updateDownloadProgress
{
- unsigned long long bytesReadSoFar = totalBytesRead;
+
// We won't update download progress until we've examined the headers, since we might need to authenticate
if (responseHeaders) {
+ unsigned long long bytesReadSoFar = totalBytesRead;
+
if (bytesReadSoFar > lastBytesRead) {
[self setLastActivityTime:[NSDate date]];
}
@@ -774,8 +776,9 @@ - (BOOL)readResponseHeadersReturningAuthenticationFailure
NSScanner *charsetScanner = [NSScanner scannerWithString: contentType];
NSString *IANAEncoding = nil;
- if ([charsetScanner scanUpToString: charsetSeparator intoString: NULL])
+ if ([charsetScanner scanUpToString: charsetSeparator intoString: NULL] && [charsetScanner scanLocation] < [contentType length])
@rbsgn

rbsgn Mar 1, 2009

Contributor

Why you’re added checking for [charsetScanner scanLocation]?

{
+ NSLog(@"%hi %hi",[charsetScanner scanLocation],[charsetSeparator length]);
[charsetScanner setScanLocation: [charsetScanner scanLocation] + [charsetSeparator length]];
[charsetScanner scanUpToString: @";" intoString: &IANAEncoding];
}
View
@@ -166,7 +166,6 @@ - (void)testCompressedResponseDownloadToFile
BOOL success = [[NSString stringWithContentsOfURL:[NSURL fileURLWithPath:path]] isEqualToString:@"This is the expected content for the first string"];
GHAssertTrue(success,@"Failed to download data to a file");
-
}
@@ -183,6 +182,12 @@ - (void)testDownloadProgress
}
+- (void)setProgress:(float)newProgress;
+{
+ progress = newProgress;
+}
+
+
- (void)testUploadProgress
{
progress = 0;
@@ -196,11 +201,6 @@ - (void)testUploadProgress
}
-- (void)setProgress:(float)newProgress;
-{
- progress = newProgress;
-}
-
- (void)testCookies
Oops, something went wrong.

1 comment on commit 2355f63

Owner

pokeb commented on 2355f63 Mar 1, 2009

Because scanUpToString: intoString: returns YES if the string isn’t present, and the call to setScanLocation: would raise an exception.

(This is why I love unit tests! I’d never have noticed that myself…)

Please sign in to comment.