Updated Branches: refs/heads/master ec1aa0602 -> 2d9bcb6ec
Fixes CB-942 - iOS failing FileTransfer malformed URL tests Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/2d9bcb6e Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/2d9bcb6e Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/2d9bcb6e Branch: refs/heads/master Commit: 2d9bcb6ec74da8937f507ce91a4dde5e22ea4857 Parents: ec1aa06 Author: Shazron Abdullah <[email protected]> Authored: Wed Jun 20 15:06:16 2012 -0700 Committer: Shazron Abdullah <[email protected]> Committed: Wed Jun 20 15:06:16 2012 -0700 ---------------------------------------------------------------------- CordovaLib/Classes/CDVFileTransfer.h | 1 + CordovaLib/Classes/CDVFileTransfer.m | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/2d9bcb6e/CordovaLib/Classes/CDVFileTransfer.h ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVFileTransfer.h b/CordovaLib/Classes/CDVFileTransfer.h index f779f7b..b9a96c9 100644 --- a/CordovaLib/Classes/CDVFileTransfer.h +++ b/CordovaLib/Classes/CDVFileTransfer.h @@ -40,6 +40,7 @@ typedef int CDVFileTransferDirection; - (void) upload:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; - (void) download:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; +- (NSString*) escapePathComponentForUrlString:(NSString*)urlString; -(NSMutableDictionary*) createFileTransferError:(int)code AndSource:(NSString*)source AndTarget:(NSString*)target; http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/2d9bcb6e/CordovaLib/Classes/CDVFileTransfer.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVFileTransfer.m b/CordovaLib/Classes/CDVFileTransfer.m index 9a3ab53..3ed09ab 100644 --- a/CordovaLib/Classes/CDVFileTransfer.m +++ b/CordovaLib/Classes/CDVFileTransfer.m @@ -21,6 +21,29 @@ @implementation CDVFileTransfer +- (NSString*) escapePathComponentForUrlString:(NSString*)urlString +{ + // separate the scheme and location components + NSArray* schemeAndLocationComponents = [urlString componentsSeparatedByString:@"://"]; + if ([schemeAndLocationComponents count] < 2) { + return urlString; + } + + // separate the domain and path components + NSArray* pathComponents = [[schemeAndLocationComponents lastObject] componentsSeparatedByString:@"/"]; + if ([pathComponents count] < 2) { + return urlString; + } + + NSString* pathComponent = [pathComponents lastObject]; + NSRange rangeOfSubstring = [urlString rangeOfString:pathComponent]; + urlString = [urlString substringToIndex:rangeOfSubstring.location]; + + pathComponent = [pathComponent stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + + return [urlString stringByAppendingString:pathComponent]; +} + - (void) upload:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options { NSString* callbackId = [arguments objectAtIndex:0]; @@ -51,7 +74,7 @@ file = [NSURL URLWithString:filePath]; } - NSURL *url = [NSURL URLWithString:[server stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; + NSURL *url = [NSURL URLWithString:[self escapePathComponentForUrlString:server]]; if (!url) { @@ -176,7 +199,7 @@ file = [NSURL URLWithString:filePath]; } - NSURL *url = [NSURL URLWithString:[sourceUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; + NSURL *url = [NSURL URLWithString:[self escapePathComponentForUrlString:sourceUrl]]; if (!url) { errorCode = INVALID_URL_ERR;
