Fixed issue with specifying an empty string for ASIFormDataRequest parameters
Added test for same issue
Showing
3 changed files
with
19 additions
and
1 deletions
@@ -212,6 +212,9 @@ static NSError *ASIUnableToCreateRequestError; | @@ -212,6 +212,9 @@ static NSError *ASIUnableToCreateRequestError; | ||
212 | - (void)appendPostData:(NSData *)data | 212 | - (void)appendPostData:(NSData *)data |
213 | { | 213 | { |
214 | [self setupPostBody]; | 214 | [self setupPostBody]; |
215 | + if ([data length] == 0) { | ||
216 | + return; | ||
217 | + } | ||
215 | if ([self shouldStreamPostDataFromDisk]) { | 218 | if ([self shouldStreamPostDataFromDisk]) { |
216 | [[self postBodyWriteStream] write:[data bytes] maxLength:[data length]]; | 219 | [[self postBodyWriteStream] write:[data bytes] maxLength:[data length]]; |
217 | } else { | 220 | } else { |
@@ -51,6 +51,21 @@ | @@ -51,6 +51,21 @@ | ||
51 | GHAssertTrue(success,@"Failed to upload the correct data (using NSData)"); | 51 | GHAssertTrue(success,@"Failed to upload the correct data (using NSData)"); |
52 | } | 52 | } |
53 | 53 | ||
54 | +// Test fix for bug where setting an empty string for a form post value would cause the rest of the post body to be ignored (because an NSOutputStream won't like it if you try to write 0 bytes) | ||
55 | +- (void)testEmptyData | ||
56 | +{ | ||
57 | + ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/post-empty"]]; | ||
58 | + [request setPostValue:@"hello" forKey:@"a_non_empty_string"]; | ||
59 | + [request setPostValue:@"" forKey:@"zzz_empty_string"]; | ||
60 | + [request setPostValue:@"there" forKey:@"xxx_non_empty_string"]; | ||
61 | + [request setShouldStreamPostDataFromDisk:YES]; | ||
62 | + [request buildPostBody]; | ||
63 | + [request start]; | ||
64 | + | ||
65 | + BOOL success = ([[request responseString] isEqualToString:@"a_non_empty_string: hello\r\nzzz_empty_string: \r\nxxx_non_empty_string: there"]); | ||
66 | + GHAssertTrue(success,@"Failed to send the correct post data"); | ||
67 | + | ||
68 | +} | ||
54 | 69 | ||
55 | 70 | ||
56 | @end | 71 | @end |
-
Please register or login to post a comment