From cbd463b0f92a79de668cab90defa62996e269ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 29 Oct 2021 17:10:04 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Better=20fix=20for=20#4267?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New helper OctoPrintClient.escapePath, does the equivalent of x.split("/").map(e => escapeURIComponent(e)).join("/"). Used in the files API client. --- src/octoprint/static/js/app/client/base.js | 6 ++++++ src/octoprint/static/js/app/client/files.js | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/octoprint/static/js/app/client/base.js b/src/octoprint/static/js/app/client/base.js index da0b54ff3..2d2d3798e 100644 --- a/src/octoprint/static/js/app/client/base.js +++ b/src/octoprint/static/js/app/client/base.js @@ -426,5 +426,11 @@ }); }; + OctoPrintClient.escapePath = function (path) { + return _.map(path.split("/"), function (p) { + return encodeURIComponent(p); + }).join("/"); + }; + return OctoPrintClient; }); diff --git a/src/octoprint/static/js/app/client/files.js b/src/octoprint/static/js/app/client/files.js index dbbde7ede..7d5458f5c 100644 --- a/src/octoprint/static/js/app/client/files.js +++ b/src/octoprint/static/js/app/client/files.js @@ -14,19 +14,19 @@ }; var resourceForLocation = function (location) { - return url + "/" + encodeURIComponent(location); + return url + "/" + OctoPrintClient.escapePath(location); }; var downloadForLocation = function (location) { - return downloadUrl + "/" + encodeURIComponent(location); + return downloadUrl + "/" + OctoPrintClient.escapePath(location); }; var downloadForEntry = function (location, filename) { - return downloadForLocation(location) + "/" + encodeURIComponent(filename); + return downloadForLocation(location) + "/" + OctoPrintClient.escapePath(filename); }; var resourceForEntry = function (location, filename) { - return resourceForLocation(location) + "/" + encodeURIComponent(filename); + return resourceForLocation(location) + "/" + OctoPrintClient.escapePath(filename); }; var preProcessList = function (response) {