From c41eedf38f2f487afa195a8c153b856d7e885224 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sat, 21 Jan 2023 15:46:44 +0100 Subject: [PATCH] Fix issue when providing a URL that ends in / (closes #2435) --- modules/sync/syncs/urlsynchronization.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/sync/syncs/urlsynchronization.cpp b/modules/sync/syncs/urlsynchronization.cpp index 9808aa2211..d481d1ae2f 100644 --- a/modules/sync/syncs/urlsynchronization.cpp +++ b/modules/sync/syncs/urlsynchronization.cpp @@ -146,7 +146,13 @@ void UrlSynchronization::start() { for (const std::string& url : _urls) { if (_filename.empty() || _urls.size() > 1) { - std::string name = std::filesystem::path(url).filename().string(); + std::filesystem::path fn = std::filesystem::path(url).filename(); + if (fn.empty() && url.back() == '/') { + // If the user provided a path that ends in / the `filename` will + // result in an empty path with causes the downloading to fail + fn = std::filesystem::path(url).parent_path().filename(); + } + std::string name = fn.string(); // We can not create filenames with question marks name.erase(std::remove(name.begin(), name.end(), '?'), name.end());