From f6a38b240d66677cdc760d99bcf95269e2c141ed Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 7 Sep 2022 15:20:25 +0200 Subject: [PATCH] Escape filename when performing PUT --- src/slic3r/Utils/OctoPrint.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/slic3r/Utils/OctoPrint.cpp b/src/slic3r/Utils/OctoPrint.cpp index 80dc43618f..51888aa95b 100644 --- a/src/slic3r/Utils/OctoPrint.cpp +++ b/src/slic3r/Utils/OctoPrint.cpp @@ -94,6 +94,20 @@ std::string substitute_host(const std::string& orig_addr, std::string sub_addr) return out; #endif } +std::string escape_url(const std::string& unescaped) +{ + std::string ret_val; + CURL* curl = curl_easy_init(); + if (curl) { + char* decoded = curl_easy_escape(curl, unescaped.c_str(), unescaped.size()); + if (decoded) { + ret_val = std::string(decoded); + curl_free(decoded); + } + curl_easy_cleanup(curl); + } + return ret_val; +} } //namespace #endif // WIN32 @@ -622,8 +636,7 @@ bool PrusaLink::put_inner(PrintHostUpload upload_data, std::string url, const st const auto upload_filename = upload_data.upload_path.filename(); const auto upload_parent_path = upload_data.upload_path.parent_path(); - - url += "/" + upload_filename.string(); + url += "/" + escape_url(upload_filename.string()); auto http = Http::put(std::move(url)); set_auth(http);