@@ -145,6 +145,37 @@ 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 (char c : pUrl) {
153+ if (isalnum (c) || 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+ std::string res;
165+
166+ for (size_t i = 0 ; i < pUrl.size (); ++i) {
167+ if ((pUrl[i] == ' %' ) && (i + 2 < pUrl.size ()) && std::isxdigit (pUrl[i + 1 ]) && std::isxdigit (pUrl[i + 2 ])) {
168+ res += static_cast <char >(std::stoi (pUrl.substr (i + 1 , 2 ), nullptr , 16 ));
169+
170+ i += 2 ;
171+ } else {
172+ res += pUrl[i];
173+ }
174+ }
175+
176+ return res;
177+ }
178+
148179#ifdef BUILDING_USING_MSVC
149180std::string forwardSlashPath (const std::string &pPath)
150181{
@@ -436,7 +467,7 @@ std::tuple<bool, std::filesystem::path> downloadFile(const std::string &pUrl)
436467
437468 curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1 );
438469 curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0 );
439- curl_easy_setopt (curl, CURLOPT_URL, pUrl.c_str ());
470+ curl_easy_setopt (curl, CURLOPT_URL, encodeUrl ( pUrl) .c_str ());
440471 curl_easy_setopt (curl, CURLOPT_WRITEDATA, static_cast <void *>(&file));
441472 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, curlWriteFunction);
442473
0 commit comments