Return-Path: X-Original-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C26B6D582 for ; Wed, 27 Jun 2012 18:33:52 +0000 (UTC) Received: (qmail 75735 invoked by uid 500); 27 Jun 2012 18:33:52 -0000 Delivered-To: apmail-incubator-callback-commits-archive@incubator.apache.org Received: (qmail 75685 invoked by uid 500); 27 Jun 2012 18:33:52 -0000 Mailing-List: contact callback-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-commits@incubator.apache.org Received: (qmail 75412 invoked by uid 99); 27 Jun 2012 18:33:52 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Jun 2012 18:33:52 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A1ED67EF4; Wed, 27 Jun 2012 18:33:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hermwong@apache.org To: callback-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [17/20] ios commit: Fixes CB-942 - iOS failing FileTransfer malformed URL tests Message-Id: <20120627183351.A1ED67EF4@tyr.zones.apache.org> Date: Wed, 27 Jun 2012 18:33:51 +0000 (UTC) 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/626c2333 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/626c2333 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/626c2333 Branch: refs/heads/master Commit: 626c2333e9bb47420c4dcd518f95b97d9f9a440c Parents: 2d00a12 Author: Shazron Abdullah Authored: Wed Jun 20 15:06:16 2012 -0700 Committer: hermwong Committed: Wed Jun 27 11:32:08 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/626c2333/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/626c2333/CordovaLib/Classes/CDVFileTransfer.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVFileTransfer.m b/CordovaLib/Classes/CDVFileTransfer.m index 8d0d7fa..e2fbdc8 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) { @@ -196,7 +219,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;