@@ -145,6 +145,39 @@ bool fuzzyCompare(double pNb1, double pNb2)
145145 return std::fabs (pNb1 - pNb2) * ONE_TRILLION <= std::fmin (std::fabs (pNb1), std::fabs (pNb2));
146146}
147147
148+ std::string encodeUrl (const std::string &pUrl)
149+ {
150+ std::ostringstream res;
151+
152+ for (const char c : pUrl) {
153+ if ((isalnum (c) != 0 ) || (std::string (" !#$&'()*+,-./:;=?@_~" ).find (c) != std::string::npos)) {
154+ res << c;
155+ } else {
156+ res << ' %' << std::uppercase << std::hex << std::setw (2 ) << std::setfill (' 0' ) << static_cast <int >(static_cast <unsigned char >(c));
157+ }
158+ }
159+ return res.str ();
160+ }
161+
162+ std::string decodeUrl (const std::string &pUrl)
163+ {
164+ static constexpr auto BASE_16 = 16 ;
165+
166+ std::string res;
167+
168+ for (size_t i = 0 ; i < pUrl.size (); ++i) {
169+ if ((pUrl[i] == ' %' ) && (i + 2 < pUrl.size ()) && (std::isxdigit (pUrl[i + 1 ]) != 0 ) && (std::isxdigit (pUrl[i + 2 ]) != 0 )) {
170+ res += static_cast <char >(std::stoi (pUrl.substr (i + 1 , 2 ), nullptr , BASE_16));
171+
172+ i += 2 ;
173+ } else {
174+ res += pUrl[i];
175+ }
176+ }
177+
178+ return res;
179+ }
180+
148181#ifdef BUILDING_USING_MSVC
149182std::string forwardSlashPath (const std::string &pPath)
150183{
@@ -436,7 +469,7 @@ std::tuple<bool, std::filesystem::path> downloadFile(const std::string &pUrl)
436469
437470 curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1 );
438471 curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0 );
439- curl_easy_setopt (curl, CURLOPT_URL, pUrl.c_str ());
472+ curl_easy_setopt (curl, CURLOPT_URL, encodeUrl ( pUrl) .c_str ());
440473 curl_easy_setopt (curl, CURLOPT_WRITEDATA, static_cast <void *>(&file));
441474 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, curlWriteFunction);
442475
0 commit comments