From df13c2bd2618bc4130fdb40eecbb1b49ead4a993 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 11 Jan 2021 02:31:51 +0100 Subject: [PATCH] Properly percent-encode URLs passed to libcurl URLs can't contain non-ASCII characters, so use wxURI to encode them properly. --- src/common/webrequest_curl.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/common/webrequest_curl.cpp b/src/common/webrequest_curl.cpp index f1458b1cd6..428bd3961d 100644 --- a/src/common/webrequest_curl.cpp +++ b/src/common/webrequest_curl.cpp @@ -22,6 +22,8 @@ #include "wx/utils.h" #endif +#include "wx/uri.h" + // Define symbols that might be missing from older libcurl headers #ifndef CURL_AT_LEAST_VERSION #define CURL_VERSION_BITS(x,y,z) ((x)<<16|(y)<<8|z) @@ -156,8 +158,10 @@ wxWebRequestCURL::wxWebRequestCURL(wxWebSession & session, curl_easy_setopt(m_handle, CURLOPT_ERRORBUFFER, m_errorBuffer); // Set this request in the private pointer curl_easy_setopt(m_handle, CURLOPT_PRIVATE, static_cast(this)); - // Set URL to handle - curl_easy_setopt(m_handle, CURLOPT_URL, static_cast(url.mb_str())); + // Set URL to handle: note that we must use wxURI to escape characters not + // allowed in the URLs correctly (URL API is only available in libcurl + // since the relatively recent v7.62.0, so we don't want to rely on it). + curl_easy_setopt(m_handle, CURLOPT_URL, wxURI(url).BuildURI().utf8_str().data()); // Set callback functions curl_easy_setopt(m_handle, CURLOPT_WRITEFUNCTION, wxCURLWriteData); curl_easy_setopt(m_handle, CURLOPT_HEADERFUNCTION, wxCURLHeader);