incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hermw...@apache.org
Subject [17/20] ios commit: Fixes CB-942 - iOS failing FileTransfer malformed URL tests
Date Wed, 27 Jun 2012 18:33:51 GMT
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 <shazron@apache.org>
Authored: Wed Jun 20 15:06:16 2012 -0700
Committer: hermwong <herm.wong@gmail.com>
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;


Mime
View raw message