cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alsoro...@apache.org
Subject cordova-plugin-file-transfer git commit: CB-10696 iOS: Encode target path with spaces
Date Thu, 06 Apr 2017 15:28:41 GMT
Repository: cordova-plugin-file-transfer
Updated Branches:
  refs/heads/master e95238e1f -> e9d93c0a5


CB-10696 iOS: Encode target path with spaces


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/e9d93c0a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/e9d93c0a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/e9d93c0a

Branch: refs/heads/master
Commit: e9d93c0a542e1b952fb742a94e711ca514148934
Parents: e95238e
Author: Nikita Matrosov <v-nimatr@microsoft.com>
Authored: Thu Apr 6 16:24:26 2017 +0300
Committer: Nikita Matrosov <v-nimatr@microsoft.com>
Committed: Thu Apr 6 16:27:07 2017 +0300

----------------------------------------------------------------------
 src/ios/CDVFileTransfer.m | 10 ++++++++++
 tests/tests.js            | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/e9d93c0a/src/ios/CDVFileTransfer.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFileTransfer.m b/src/ios/CDVFileTransfer.m
index 9b01049..ab59012 100644
--- a/src/ios/CDVFileTransfer.m
+++ b/src/ios/CDVFileTransfer.m
@@ -440,6 +440,13 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
         targetURL = [[self.commandDelegate getCommandInstance:@"File"] fileSystemURLforLocalPath:target].url;
     } else {
         targetURL = [NSURL URLWithString:target];
+
+        if (targetURL == nil) {
+            NSString* targetUrlTextEscaped = [target stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet
URLFragmentAllowedCharacterSet]];
+            if (targetUrlTextEscaped) {
+                targetURL = [NSURL URLWithString:targetUrlTextEscaped];
+            }
+        }
     }
 
     NSURL* sourceURL = [NSURL URLWithString:source];
@@ -447,6 +454,9 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
     if (!sourceURL) {
         errorCode = INVALID_URL_ERR;
         NSLog(@"File Transfer Error: Invalid server URL %@", source);
+    } else if (!targetURL) {
+        errorCode = INVALID_URL_ERR;
+        NSLog(@"File Tranfer Error: Invalid target URL %@", target);
     } else if (![targetURL isFileURL]) {
         CDVFilesystemURL *fsURL = [CDVFilesystemURL fileSystemURLWithString:target];
         if (!fsURL) {

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/e9d93c0a/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 98acb4c..0efc64e 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -398,6 +398,47 @@ exports.defineAutoTests = function () {
                     specContext.transfer.download(fileURL, specContext.localFilePath, downloadWin,
downloadFail);
                 }, DOWNLOAD_TIMEOUT * 10); // to give Heroku server some time to wake up
 
+                it("filetransfer.spec.4.1 should download a file using target name with space",
function (done) {
+
+                    var fileURL = SERVER + "/robots.txt";
+                    this.fileName = "test file.txt";
+                    this.localFilePath = this.root.toURL() + this.fileName;
+
+                    var specContext = this;
+
+                    var fileWin = function (blob) {
+
+                        if (specContext.transfer.onprogress.calls.any()) {
+                            var lastProgressEvent = specContext.transfer.onprogress.calls.mostRecent().args[0];
+                            expect(lastProgressEvent.loaded).not.toBeGreaterThan(blob.size);
+                        } else {
+                            console.log("no progress events were emitted");
+                        }
+
+                        done();
+                    };
+
+                    var fileSystemFail = function() {
+                        unexpectedCallbacks.fileSystemFail();
+                        done();
+                    };
+
+                    var downloadFail = function() {
+                        unexpectedCallbacks.httpFail();
+                        done();
+                    };
+
+                    var downloadWin = function (entry) {
+
+                        verifyDownload(entry, specContext);
+
+                        // verify the FileEntry representing this file
+                        entry.file(fileWin, fileSystemFail);
+                    };
+
+                    specContext.transfer.download(fileURL, specContext.localFilePath, downloadWin,
downloadFail);
+                }, DOWNLOAD_TIMEOUT);
+
                 it("filetransfer.spec.5 should download a file using http basic auth", function
(done) {
                     var fileURL = SERVER_WITH_CREDENTIALS + "/download_basic_auth";
                     var specContext = this;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message