Permalink
Browse files

Fixed issue with specifying an empty string for ASIFormDataRequest pa…

…rameters

Added test for same issue
  • Loading branch information...
1 parent 03a71b6 commit 194cc4035fc8d6288122a30e5420b20b9d402639 @pokeb pokeb committed Jun 16, 2009
Showing with 19 additions and 1 deletion.
  1. +3 −0 Classes/ASIHTTPRequest.m
  2. +1 −1 Classes/Tests/ASIFormDataRequestTests.h
  3. +15 −0 Classes/Tests/ASIFormDataRequestTests.m
View
@@ -212,6 +212,9 @@ - (void)setupPostBody
- (void)appendPostData:(NSData *)data
{
[self setupPostBody];
+ if ([data length] == 0) {
+ return;
+ }
if ([self shouldStreamPostDataFromDisk]) {
[[self postBodyWriteStream] write:[data bytes] maxLength:[data length]];
} else {
@@ -17,5 +17,5 @@
}
- (void)testPostWithFileUpload;
-
+- (void)testEmptyData;
@end
@@ -51,6 +51,21 @@ - (void)testPostWithFileUpload
GHAssertTrue(success,@"Failed to upload the correct data (using NSData)");
}
+// 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)
+- (void)testEmptyData
+{
+ ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/post-empty"]];
+ [request setPostValue:@"hello" forKey:@"a_non_empty_string"];
+ [request setPostValue:@"" forKey:@"zzz_empty_string"];
+ [request setPostValue:@"there" forKey:@"xxx_non_empty_string"];
+ [request setShouldStreamPostDataFromDisk:YES];
+ [request buildPostBody];
+ [request start];
+
+ BOOL success = ([[request responseString] isEqualToString:@"a_non_empty_string: hello\r\nzzz_empty_string: \r\nxxx_non_empty_string: there"]);
+ GHAssertTrue(success,@"Failed to send the correct post data");
+
+}
@end

0 comments on commit 194cc40

Please sign in to comment.