mirror of
https://github.com/apache/cordova-plugin-file-transfer.git
synced 2026-04-28 00:02:49 +08:00
CB-10696 iOS: Encode target path with spaces
This commit is contained in:
@@ -440,6 +440,13 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
|
|||||||
targetURL = [[self.commandDelegate getCommandInstance:@"File"] fileSystemURLforLocalPath:target].url;
|
targetURL = [[self.commandDelegate getCommandInstance:@"File"] fileSystemURLforLocalPath:target].url;
|
||||||
} else {
|
} else {
|
||||||
targetURL = [NSURL URLWithString:target];
|
targetURL = [NSURL URLWithString:target];
|
||||||
|
|
||||||
|
if (targetURL == nil) {
|
||||||
|
NSString* targetUrlTextEscaped = [target stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
|
||||||
|
if (targetUrlTextEscaped) {
|
||||||
|
targetURL = [NSURL URLWithString:targetUrlTextEscaped];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NSURL* sourceURL = [NSURL URLWithString:source];
|
NSURL* sourceURL = [NSURL URLWithString:source];
|
||||||
@@ -447,6 +454,9 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
|
|||||||
if (!sourceURL) {
|
if (!sourceURL) {
|
||||||
errorCode = INVALID_URL_ERR;
|
errorCode = INVALID_URL_ERR;
|
||||||
NSLog(@"File Transfer Error: Invalid server URL %@", source);
|
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]) {
|
} else if (![targetURL isFileURL]) {
|
||||||
CDVFilesystemURL *fsURL = [CDVFilesystemURL fileSystemURLWithString:target];
|
CDVFilesystemURL *fsURL = [CDVFilesystemURL fileSystemURLWithString:target];
|
||||||
if (!fsURL) {
|
if (!fsURL) {
|
||||||
|
|||||||
@@ -398,6 +398,47 @@ exports.defineAutoTests = function () {
|
|||||||
specContext.transfer.download(fileURL, specContext.localFilePath, downloadWin, downloadFail);
|
specContext.transfer.download(fileURL, specContext.localFilePath, downloadWin, downloadFail);
|
||||||
}, DOWNLOAD_TIMEOUT * 10); // to give Heroku server some time to wake up
|
}, 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) {
|
it("filetransfer.spec.5 should download a file using http basic auth", function (done) {
|
||||||
var fileURL = SERVER_WITH_CREDENTIALS + "/download_basic_auth";
|
var fileURL = SERVER_WITH_CREDENTIALS + "/download_basic_auth";
|
||||||
var specContext = this;
|
var specContext = this;
|
||||||
|
|||||||
Reference in New Issue
Block a user