in src/Windows/curl_easy.cpp [419:467]
std::string curl_easy::unescape(const std::string& encoded) const
{
std::string decodedHeader;
for (auto it = encoded.begin(); it != encoded.end(); ++it)
{
if (*it == '%')
{
char byteValue;
++it;
if (it == encoded.end())
{
throw_on_error(
EBADMSG, "Malformed URL encoding in header " + encoded);
}
char ch = *it;
int8_t hexValue = Int8FromHexAscii(ch);
if (hexValue < 0)
{
std::stringstream ss;
ss << "Bogus hex value " << (uint8_t)ch << "(" << ch
<< ") in URL encoding in header " << encoded;
throw_on_error(EBADMSG, ss.str());
}
byteValue = hexValue << 4;
++it;
if (it == encoded.end())
{
throw_on_error(
EBADMSG, "Malformed URL encoding in header " + encoded);
}
ch = *it;
hexValue = Int8FromHexAscii(ch);
if (hexValue < 0)
{
std::stringstream ss;
ss << "Bogus hex value " << (uint8_t)ch << "(" << ch
<< ") in URL encoding in header " << encoded;
throw_on_error(EBADMSG, ss.str());
}
byteValue |= hexValue & 0xf;
decodedHeader.push_back(byteValue);
}
else
{
decodedHeader.push_back(*it);
}
}
return decodedHeader;
}