From a2fc510f7225791253c128041c68f62760687628 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 5 Oct 2012 10:09:13 -0700 Subject: [PATCH] Enforcing 'this parameter must not be nil' by using NSCParameterAssert() --- AFNetworking/AFHTTPClient.h | 6 +++--- AFNetworking/AFHTTPClient.m | 15 +++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index ce5b436..0e2c77a 100755 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -131,7 +131,7 @@ typedef enum { /** Creates and initializes an `AFHTTPClient` object with the specified base URL. - @param url The base URL for the HTTP client. This argument must not be nil. + @param url The base URL for the HTTP client. This argument must not be `nil`. @return The newly-initialized HTTP client */ @@ -510,7 +510,7 @@ extern NSTimeInterval const kAFUploadStream3GSuggestedDelay; /** Appends the HTTP header `Content-Disposition: file; filename=#{generated filename}; name=#{name}"` and `Content-Type: #{generated mimeType}`, followed by the encoded file data and the multipart form boundary. - @param fileURL The URL corresponding to the file whose content will be appended to the form. + @param fileURL The URL corresponding to the file whose content will be appended to the form. This parameter must not be `nil`. @param name The name to be associated with the specified data. This parameter must not be `nil`. @param error If an error occurs, upon return contains an `NSError` object that describes the problem. @@ -527,8 +527,8 @@ extern NSTimeInterval const kAFUploadStream3GSuggestedDelay; @param data The data to be encoded and appended to the form data. @param name The name to be associated with the specified data. This parameter must not be `nil`. - @param mimeType The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be `nil`. @param filename The filename to be associated with the specified data. This parameter must not be `nil`. + @param mimeType The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be `nil`. */ - (void)appendPartWithFileData:(NSData *)data name:(NSString *)name diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index e3b2ec9..ccc4cfe 100755 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -231,14 +231,12 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) { } - (id)initWithBaseURL:(NSURL *)url { + NSCParameterAssert(url); + self = [super init]; if (!self) { return nil; } - - if (!url) { - [NSException raise:@"-[AFHTTPClient initWithBaseURL:] nil URL" format:@"`url` must not be nil"]; - } // Ensure terminal slash for baseURL path, so that NSURL +URLWithString:relativeToURL: works as expected if ([[url path] length] > 0 && ![[url absoluteString] hasSuffix:@"/"]) { @@ -781,6 +779,9 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2; name:(NSString *)name error:(NSError * __autoreleasing *)error { + NSCParameterAssert(fileURL); + NSCParameterAssert(name); + if (![fileURL isFileURL]) { NSDictionary *userInfo = [NSDictionary dictionaryWithObject:NSLocalizedString(@"Expected URL to be a file URL", nil) forKey:NSLocalizedFailureReasonErrorKey]; if (error != NULL) { @@ -819,6 +820,10 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2; fileName:(NSString *)fileName mimeType:(NSString *)mimeType { + NSCParameterAssert(name); + NSCParameterAssert(fileName); + NSCParameterAssert(mimeType); + NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary]; [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"]; [mutableHeaders setValue:mimeType forKey:@"Content-Type"]; @@ -829,6 +834,8 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2; - (void)appendPartWithFormData:(NSData *)data name:(NSString *)name { + NSCParameterAssert(name); + NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary]; [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"", name] forKey:@"Content-Disposition"];