From babd06c1f891b23fffc170e878f0e10279aa7ebd Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Fri, 14 Jun 2013 17:34:35 +0100 Subject: [PATCH] Don't let AFURLConnectionOperation accept a nil request Closes #1064 --- AFNetworking/AFURLConnectionOperation.m | 2 ++ Tests/AFURLConnectionOperationTests.m | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index 52fe7f9..71d34f2 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -267,6 +267,8 @@ static BOOL AFSecKeyIsEqualToKey(SecKeyRef key1, SecKeyRef key2) { #endif - (id)initWithRequest:(NSURLRequest *)urlRequest { + NSParameterAssert(urlRequest); + self = [super init]; if (!self) { return nil; diff --git a/Tests/AFURLConnectionOperationTests.m b/Tests/AFURLConnectionOperationTests.m index 7982789..4b3cbe3 100644 --- a/Tests/AFURLConnectionOperationTests.m +++ b/Tests/AFURLConnectionOperationTests.m @@ -37,6 +37,10 @@ #pragma mark - +- (void)testInitWithNilRequestRaisesException { + expect(^{ (void)[[AFURLConnectionOperation alloc] initWithRequest:nil]; }).to.raiseAny(); +} + - (void)testThatAFURLConnectionOperationInvokesWillSendRequestForAuthenticationChallengeBlock { NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/path" relativeToURL:self.baseURL]]; AFURLConnectionOperation *operation = [[AFURLConnectionOperation alloc] initWithRequest:request];