summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-09-16 12:19:24 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-09-16 12:19:37 (GMT)
commit98f78af88b253de8762f6238f35f09c4079840c0 (patch)
tree540bf6bf54c94c41f0dade905c55e9e0b3501b5b /Source
parentb3f4a05761ba0da44e4bfe702af939ecda76f96f (diff)
parent412189bce78a9862e22853ec29ae73de4885eb27 (diff)
downloadCMake-98f78af88b253de8762f6238f35f09c4079840c0.zip
CMake-98f78af88b253de8762f6238f35f09c4079840c0.tar.gz
CMake-98f78af88b253de8762f6238f35f09c4079840c0.tar.bz2
Merge topic 'update-curl'
412189bce7 curl: Set build options the way we need for CMake 8ecd95845c Merge branch 'upstream-curl' into update-curl 386467c9dc curl 2021-09-14 (8e82f2a0) a8ae9c7055 curl: Update script to get curl 7.79.0 3cfd89add5 cmCurl: Fix file:// URLs with spaces for curl 7.78+ 63b5a6869e cmCurl: Adopt helper to fix file:// URLs Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !6523
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCurl.cxx42
-rw-r--r--Source/cmCurl.h1
-rw-r--r--Source/cmFileCommand.cxx37
3 files changed, 44 insertions, 36 deletions
diff --git a/Source/cmCurl.cxx b/Source/cmCurl.cxx
index 233790e..fa001d2 100644
--- a/Source/cmCurl.cxx
+++ b/Source/cmCurl.cxx
@@ -5,9 +5,17 @@
#if !defined(CMAKE_USE_SYSTEM_CURL) && !defined(_WIN32) && \
!defined(__APPLE__) && !defined(CURL_CA_BUNDLE) && !defined(CURL_CA_PATH)
# define CMAKE_FIND_CAFILE
-# include "cmSystemTools.h"
#endif
#include "cmStringAlgorithms.h"
+#include "cmSystemTools.h"
+
+#if defined(_WIN32)
+# include <vector>
+
+# include <windows.h>
+
+# include "cmsys/Encoding.hxx"
+#endif
// curl versions before 7.21.5 did not provide this error code
#if defined(LIBCURL_VERSION_NUM) && LIBCURL_VERSION_NUM < 0x071505
@@ -95,3 +103,35 @@ std::string cmCurlSetNETRCOption(::CURL* curl, const std::string& 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");
+
+#if defined(_WIN32)
+ // libcurl doesn't support file:// urls for unicode filenames on Windows.
+ // Convert string from UTF-8 to ACP if this is a file:// URL.
+ std::wstring wurl = cmsys::Encoding::ToWide(url);
+ if (!wurl.empty()) {
+ int mblen =
+ WideCharToMultiByte(CP_ACP, 0, wurl.c_str(), -1, NULL, 0, NULL, NULL);
+ if (mblen > 0) {
+ std::vector<char> chars(mblen);
+ mblen = WideCharToMultiByte(CP_ACP, 0, wurl.c_str(), -1, &chars[0],
+ mblen, NULL, NULL);
+ if (mblen > 0) {
+ url = &chars[0];
+ }
+ }
+ }
+#endif
+
+ return url;
+}
diff --git a/Source/cmCurl.h b/Source/cmCurl.h
index fb716f8..9c1e337 100644
--- a/Source/cmCurl.h
+++ b/Source/cmCurl.h
@@ -11,3 +11,4 @@
std::string cmCurlSetCAInfo(::CURL* curl, const char* cafile = nullptr);
std::string cmCurlSetNETRCOption(::CURL* curl, const std::string& netrc_level,
const std::string& netrc_file);
+std::string cmCurlFixFileURL(std::string url);
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 2730a07..1223d2a 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -65,37 +65,8 @@
# include "cmFileLockResult.h"
#endif
-#if defined(_WIN32)
-# include <windows.h>
-#endif
-
namespace {
-#if defined(_WIN32)
-// libcurl doesn't support file:// urls for unicode filenames on Windows.
-// Convert string from UTF-8 to ACP if this is a file:// URL.
-std::string fix_file_url_windows(const std::string& url)
-{
- std::string ret = url;
- if (strncmp(url.c_str(), "file://", 7) == 0) {
- std::wstring wurl = cmsys::Encoding::ToWide(url);
- if (!wurl.empty()) {
- int mblen =
- WideCharToMultiByte(CP_ACP, 0, wurl.c_str(), -1, NULL, 0, NULL, NULL);
- if (mblen > 0) {
- std::vector<char> chars(mblen);
- mblen = WideCharToMultiByte(CP_ACP, 0, wurl.c_str(), -1, &chars[0],
- mblen, NULL, NULL);
- if (mblen > 0) {
- ret = &chars[0];
- }
- }
- }
- }
- return ret;
-}
-#endif
-
bool HandleWriteImpl(std::vector<std::string> const& args, bool append,
cmExecutionStatus& status)
{
@@ -1976,9 +1947,7 @@ bool HandleDownloadCommand(std::vector<std::string> const& args,
}
}
-# if defined(_WIN32)
- url = fix_file_url_windows(url);
-# endif
+ url = cmCurlFixFileURL(url);
::CURL* curl;
::curl_global_init(CURL_GLOBAL_DEFAULT);
@@ -2292,9 +2261,7 @@ bool HandleUploadCommand(std::vector<std::string> const& args,
unsigned long file_size = cmsys::SystemTools::FileLength(filename);
-# if defined(_WIN32)
- url = fix_file_url_windows(url);
-# endif
+ url = cmCurlFixFileURL(url);
::CURL* curl;
::curl_global_init(CURL_GLOBAL_DEFAULT);