fix #5 use curl_unescape to decode URL

pull/23/head
JuanJakobo 2021-02-03 18:54:07 +01:00
parent bfe632f67e
commit 4793862a11
1 changed files with 9 additions and 81 deletions

View File

@ -10,6 +10,7 @@
#include <string> #include <string>
#include <math.h> #include <math.h>
#include <curl/curl.h>
using std::string; using std::string;
@ -75,85 +76,12 @@ string Util::getXMLAttribute(const string &buffer, const string &name)
void Util::decodeUrl(string &item) void Util::decodeUrl(string &item)
{ {
string buffer; char *buffer;
buffer.reserve(item.size()); CURL *curl = curl_easy_init();
for (size_t pos = 0; pos != item.size(); ++pos)
{ buffer = curl_easy_unescape(curl,item.c_str(),0,NULL);
string temp = item.substr(pos, 3); item = buffer;
if (temp == "%20")
{ curl_free(buffer)
buffer.append(" "); curl_easy_cleanup(curl);
pos = pos + 2;
}
else if (temp == "%21")
{
buffer.append("!");
pos = pos + 2;
}
else if (temp == "%22")
{
buffer.append("\"");
pos = pos + 2;
}
else if (temp == "%23")
{
buffer.append("#");
pos = pos + 2;
}
else if (temp == "%24")
{
buffer.append("$");
pos = pos + 2;
}
else if (temp == "%25")
{
buffer.append("%");
pos = pos + 2;
}
else if (temp == "%26")
{
buffer.append("&");
pos = pos + 2;
}
else if (temp == "%27")
{
buffer.append("'");
pos = pos + 2;
}
else if (temp == "%28")
{
buffer.append("(");
pos = pos + 2;
}
else if (temp == "%29")
{
buffer.append(")");
pos = pos + 2;
}
else if (temp == "%2a")
{
buffer.append("*");
pos = pos + 2;
}
else if (temp == "%2b")
{
buffer.append("+");
pos = pos + 2;
}
else if (temp == "%2c")
{
buffer.append(",");
pos = pos + 2;
}
else if (temp == "%3f")
{
buffer.append("?");
pos = pos + 2;
}
else
{
buffer.append(&item[pos], 1);
}
}
item.swap(buffer);
} }