From 3c17ad30e15a3185549a095cf0b11d5c0797a0d0 Mon Sep 17 00:00:00 2001 From: Romain Cazier Date: Sat, 19 Feb 2022 14:22:29 +0100 Subject: [PATCH] Updates to b.download() to avoid the query string to be stripped by the shell (because of the "&") and make sure all spaces are escaped in download paths --- basil.js | 12 +++++++----- src/includes/input.js | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/basil.js b/basil.js index f0d4b3d8..1d28efc5 100644 --- a/basil.js +++ b/basil.js @@ -5117,7 +5117,7 @@ pub.shellExecute = function(cmd) { * @param {String|File} [file] A relative file path in the project folder or a File instance */ pub.download = function(url, file) { - var projPath = pub.projectFolder().fsName.replace(" ", "\\ "); + var projPath = pub.projectFolder().fsName.replace(/ /g, "\\ "); // var scriptPath = "~/Documents/basiljs/bundle/lib/download.sh"; // This is more portable then a fixed location // the Script looks for the lib folder next to itself @@ -5169,12 +5169,14 @@ pub.download = function(url, file) { if (isURL(url)) { var cmd = null; + url = "\"" + url + "\""; + if (file) { if (file instanceof File) { var downloadFolder = file.parent.fsName; var fileName = file.displayName; - downloadFolder = downloadFolder.replace(" ", "\\ "); - fileName = fileName.replace(" ", "\\ "); + downloadFolder = downloadFolder.replace(/ /g, "\\ "); + fileName = fileName.replace(/ /g, "\\ "); cmd = ["sh", scriptPath, downloadFolder, url, fileName].join(" "); } else { @@ -5185,8 +5187,8 @@ pub.download = function(url, file) { if(startsWith(downloadFolder, "./")) downloadFolder.substr(2); if(startsWith(downloadFolder, "/")) downloadFolder.substr(1); - downloadFolder = downloadFolder.replace(" ", "\\ "); - fileName = fileName.replace(" ", "\\ "); + downloadFolder = downloadFolder.replace(/ /g, "\\ "); + fileName = fileName.replace(/ /g, "\\ "); downloadFolder = projPath + "/data/" + downloadFolder; cmd = ["sh", scriptPath, downloadFolder, url, fileName].join(" "); diff --git a/src/includes/input.js b/src/includes/input.js index 9ee31e60..e604f76d 100644 --- a/src/includes/input.js +++ b/src/includes/input.js @@ -46,7 +46,7 @@ pub.shellExecute = function(cmd) { * @param {String|File} [file] A relative file path in the project folder or a File instance */ pub.download = function(url, file) { - var projPath = pub.projectFolder().fsName.replace(" ", "\\ "); + var projPath = pub.projectFolder().fsName.replace(/ /g, "\\ "); // var scriptPath = "~/Documents/basiljs/bundle/lib/download.sh"; // This is more portable then a fixed location // the Script looks for the lib folder next to itself @@ -98,12 +98,14 @@ pub.download = function(url, file) { if (isURL(url)) { var cmd = null; + url = "\"" + url + "\""; + if (file) { if (file instanceof File) { var downloadFolder = file.parent.fsName; var fileName = file.displayName; - downloadFolder = downloadFolder.replace(" ", "\\ "); - fileName = fileName.replace(" ", "\\ "); + downloadFolder = downloadFolder.replace(/ /g, "\\ "); + fileName = fileName.replace(/ /g, "\\ "); cmd = ["sh", scriptPath, downloadFolder, url, fileName].join(" "); } else { @@ -114,8 +116,8 @@ pub.download = function(url, file) { if(startsWith(downloadFolder, "./")) downloadFolder.substr(2); if(startsWith(downloadFolder, "/")) downloadFolder.substr(1); - downloadFolder = downloadFolder.replace(" ", "\\ "); - fileName = fileName.replace(" ", "\\ "); + downloadFolder = downloadFolder.replace(/ /g, "\\ "); + fileName = fileName.replace(/ /g, "\\ "); downloadFolder = projPath + "/data/" + downloadFolder; cmd = ["sh", scriptPath, downloadFolder, url, fileName].join(" ");