diff --git a/Source/cmCurl.cxx b/Source/cmCurl.cxx index 7dc6b7cf1b..ab30dc6658 100644 --- a/Source/cmCurl.cxx +++ b/Source/cmCurl.cxx @@ -227,20 +227,6 @@ std::string cmCurlSetNETRCOption(::CURL* curl, std::string const& netrc_level, return e; } -std::string cmCurlFixFileURL(std::string url) -{ - if (!cmHasLiteralPrefix(url, "file://")) { - return url; - } - - // libcurl 7.77 and below accidentally allowed spaces in URLs in some cases. - // One such case was file:// URLs, which CMake has long accepted as a result. - // Explicitly encode spaces for a URL. - cmSystemTools::ReplaceString(url, " ", "%20"); - - return url; -} - ::CURL* cm_curl_easy_init() { ::CURL* curl = curl_easy_init(); diff --git a/Source/cmCurl.h b/Source/cmCurl.h index 3d606715ad..321ef5a1b6 100644 --- a/Source/cmCurl.h +++ b/Source/cmCurl.h @@ -21,7 +21,6 @@ cm::optional cmCurlPrintTLSVersion(int curl_tls_version); std::string cmCurlSetCAInfo(::CURL* curl, std::string const& cafile = {}); std::string cmCurlSetNETRCOption(::CURL* curl, std::string const& netrc_level, std::string const& netrc_file); -std::string cmCurlFixFileURL(std::string url); ::CURLcode cm_curl_global_init(long flags); ::CURL* cm_curl_easy_init(); diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index f964367a3b..72a62b2078 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -1698,6 +1698,16 @@ std::string const TLS_VERSION_DEFAULT = "1.2"; // Stuff for curl download/upload using cmFileCommandVectorOfChar = std::vector; +std::string CurlCompatFileURL(std::string url) +{ + if (cmHasLiteralPrefix(url, "file://")) { + // libcurl 7.77 and below accidentally allowed spaces in file:// URLs, + // which CMake has long accepted as a result. Explicitly encode spaces. + cmSystemTools::ReplaceString(url, " ", "%20"); + } + return url; +} + size_t cmWriteToFileCallback(void* ptr, size_t size, size_t nmemb, void* data) { int realsize = static_cast(size * nmemb); @@ -2139,7 +2149,7 @@ bool HandleDownloadCommand(std::vector const& args, } } - url = cmCurlFixFileURL(url); + url = CurlCompatFileURL(url); ::CURL* curl; cm_curl_global_init(CURL_GLOBAL_DEFAULT); @@ -2541,7 +2551,7 @@ bool HandleUploadCommand(std::vector const& args, unsigned long file_size = cmsys::SystemTools::FileLength(filename); - url = cmCurlFixFileURL(url); + url = CurlCompatFileURL(url); ::CURL* curl; cm_curl_global_init(CURL_GLOBAL_DEFAULT);