DinaGala / 42_webserv

This project is about writing our own HTTP server.
2 stars 2 forks source link

Special characters in url #34

Closed nuferron closed 1 month ago

nuferron commented 2 months ago

discuss what to do and implement it (in case implementation is need it)

nuferron commented 2 months ago

fixed! urlDecode is now in Response, but should be in Request. I'll close the issue then

nuferron commented 2 months ago

I'll leave this here so it won't be lost

std::string Response::urlDecode(const std::string &encoded)
{
    std::string decoded;
    size_t      len = encoded.size();

    for (size_t i = 0; i < len; i++)
    {
        if (encoded[i] == '%')
        {
            decoded += static_cast<char>(strToHex(encoded.substr(i + 1, 2)));
            i += 2;
        }
        else if (encoded[i] == '+')
            decoded += ' ';
        else
            decoded += encoded[i];
    }
    return (decoded);
}