From 0c1ca7ecd087401b867dac61111a9971542ac7ed Mon Sep 17 00:00:00 2001 From: Matt Smollinger Date: Thu, 3 Mar 2016 08:15:15 -0500 Subject: [PATCH 1/2] Prevent objects that are already percent encoded from being double encoded Fixes #121 --- FPPicker/Shared/FPLibrary.h | 7 +++++++ FPPicker/Shared/FPLibrary.m | 27 +++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/FPPicker/Shared/FPLibrary.h b/FPPicker/Shared/FPLibrary.h index 365688d..8533788 100644 --- a/FPPicker/Shared/FPLibrary.h +++ b/FPPicker/Shared/FPLibrary.h @@ -43,6 +43,13 @@ andMimetypes:(NSArray *)mimetypes cachePolicy:(NSURLRequestCachePolicy)policy; ++ (NSURLRequest *)requestForLoadPath:(NSString *)loadpath + withFormat:(NSString *)type + queryString:(NSString *)queryString + andMimetypes:(NSArray *)mimetypes + cachePolicy:(NSURLRequestCachePolicy)policy + shouldURLEncode:(BOOL)encode; + #ifdef FPLibrary_protected + (void)uploadLocalURLToFilepicker:(NSURL *)localURL diff --git a/FPPicker/Shared/FPLibrary.m b/FPPicker/Shared/FPLibrary.m index 181e0b6..3c7ad9e 100644 --- a/FPPicker/Shared/FPLibrary.m +++ b/FPPicker/Shared/FPLibrary.m @@ -25,7 +25,8 @@ + (void)requestObjectMediaInfo:(NSDictionary *)obj withFormat:@"data" queryString:nil andMimetypes:source.mimetypes - cachePolicy:NSURLRequestReloadRevalidatingCacheData]; + cachePolicy:NSURLRequestReloadRevalidatingCacheData + shouldURLEncode:NO]; NSString *tempPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[FPUtils genRandStringLength:20]]; @@ -281,6 +282,21 @@ + (NSURLRequest *)requestForLoadPath:(NSString *)loadpath queryString:(NSString *)queryString andMimetypes:(NSArray *)mimetypes cachePolicy:(NSURLRequestCachePolicy)policy +{ + [self requestForLoadPath:loadpath + withFormat:type + queryString:queryString + andMimetypes:mimetypes + cachePolicy:policy + shouldURLEncode:YES]; +} + ++ (NSURLRequest *)requestForLoadPath:(NSString *)loadpath + withFormat:(NSString *)type + queryString:(NSString *)queryString + andMimetypes:(NSArray *)mimetypes + cachePolicy:(NSURLRequestCachePolicy)policy + shouldURLEncode:(BOOL)encode; { FPSession *fpSession = [FPSession sessionForFileUploads]; fpSession.mimetypes = mimetypes; @@ -289,7 +305,14 @@ + (NSURLRequest *)requestForLoadPath:(NSString *)loadpath NSURLComponents *urlComponents = [NSURLComponents componentsWithString:fpBASE_URL]; urlComponents.query = queryString; - urlComponents.path = [NSString stringWithFormat:@"/api/path%@", loadpath]; + if (encode) + { + urlComponents.path = [NSString stringWithFormat:@"/api/path%@", loadpath]; + } + else + { + urlComponents.percentEncodedPath = [NSString stringWithFormat:@"/api/path%@", loadpath]; + } NSArray *queryItems = @[ [NSURLQueryItem queryItemWithName:@"format" value:type], From 1e745e0f7240d913c8f383a6ed4ac5ac5709ac75 Mon Sep 17 00:00:00 2001 From: Matt Smollinger Date: Fri, 4 Mar 2016 08:33:47 -0500 Subject: [PATCH 2/2] Fix Missing Return --- FPPicker/Shared/FPLibrary.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/FPPicker/Shared/FPLibrary.m b/FPPicker/Shared/FPLibrary.m index 3c7ad9e..b2d5f20 100644 --- a/FPPicker/Shared/FPLibrary.m +++ b/FPPicker/Shared/FPLibrary.m @@ -283,12 +283,12 @@ + (NSURLRequest *)requestForLoadPath:(NSString *)loadpath andMimetypes:(NSArray *)mimetypes cachePolicy:(NSURLRequestCachePolicy)policy { - [self requestForLoadPath:loadpath - withFormat:type - queryString:queryString - andMimetypes:mimetypes - cachePolicy:policy - shouldURLEncode:YES]; + return [self requestForLoadPath:loadpath + withFormat:type + queryString:queryString + andMimetypes:mimetypes + cachePolicy:policy + shouldURLEncode:YES]; } + (NSURLRequest *)requestForLoadPath:(NSString *)loadpath