فهرست منبع

Fix for crashes due to dangerous NSMutableDictionary access in AFHTTPRequestSerialiser – Moved unit test to a better location.

Alex Bird 9 سال پیش
والد
کامیت
0e46d1ea89
2فایلهای تغییر یافته به همراه22 افزوده شده و 22 حذف شده
  1. 22 0
      Tests/Tests/AFHTTPRequestSerializationTests.m
  2. 0 22
      Tests/Tests/AFJSONSerializationTests.m

+ 22 - 0
Tests/Tests/AFHTTPRequestSerializationTests.m

@@ -183,6 +183,28 @@
     XCTAssertFalse([serializer.HTTPRequestHeaders.allKeys containsObject:headerField]);
 }
 
+- (void)testThatHTTPHeaderValueCanBeSetToReferenceCountedStringFromMultipleThreadsWithoutCrashing {
+    @autoreleasepool {
+        int dispatchTarget = 1000;
+        __block int completionCount = 0;
+        for(int i=0; i<dispatchTarget; i++) {
+            NSString *nonStaticNonTaggedPointerString = [NSString stringWithFormat:@"%@", [NSDate dateWithTimeIntervalSince1970:i]];
+            dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul);
+            dispatch_async(queue, ^{
+                
+                [self.requestSerializer setValue:nonStaticNonTaggedPointerString forHTTPHeaderField:@"FrequentlyUpdatedHeaderField"];
+                
+                dispatch_sync(dispatch_get_main_queue(), ^{
+                    completionCount++;
+                });
+            });
+        }
+        while (completionCount < dispatchTarget) {
+            [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
+        }
+    } // Test succeeds if it does not EXC_BAD_ACCESS when cleaning up the @autoreleasepool
+}
+
 #pragma mark - Helper Methods
 
 - (void)testQueryStringFromParameters {

+ 0 - 22
Tests/Tests/AFJSONSerializationTests.m

@@ -66,28 +66,6 @@ static NSData * AFJSONTestData() {
     XCTAssertTrue([@"[{\"key\":\"value\"}]" isEqualToString:body], @"Parameters were not encoded correctly");
 }
 
-- (void)testThatJSONRequestSerializationHandlesHeaderValueSetToReferenceCountedStringFromMultipleThreads {
-    @autoreleasepool {
-        int dispatchTarget = 1000;
-        __block int completionCount = 0;
-        for(int i=0; i<dispatchTarget; i++) {
-            NSString *nonStaticNonTaggedPointerString = [NSString stringWithFormat:@"%@", [NSDate dateWithTimeIntervalSince1970:i]];
-            dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul);
-            dispatch_async(queue, ^{
-                
-                [self.requestSerializer setValue:nonStaticNonTaggedPointerString forHTTPHeaderField:@"FrequentlyUpdatedHeaderField"];
-                
-                dispatch_sync(dispatch_get_main_queue(), ^{
-                    completionCount++;
-                });
-            });
-        }
-        while (completionCount < dispatchTarget) {
-            [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
-        }
-    } // Test succeeds if it does not EXC_BAD_ACCESS when cleaning up the @autoreleasepool
-}
-
 @end
 
 #pragma mark -