Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: BlueHazzard on February 03, 2015, 12:36:32 am

Title: What does "URLEncode" stand for?
Post by: BlueHazzard on February 03, 2015, 12:36:32 am
Hi, i try to write a test bench for the scripting binding, and found this function:

Code
wxString URLEncode(const wxString &str) // not sure this is 100% standards compliant, but I hope so
{
    wxString ret;
    wxString t;
    for (unsigned int i = 0; i < str.length(); ++i)
    {
        wxChar c = str[i];
        if (  (c >= _T('A') && c <= _T('Z'))
           || (c >= _T('a') && c <= _T('z'))
           || (c >= _T('0') && c <= _T('9'))
           || (c == _T('.'))
           || (c == _T('-'))
           || (c == _T('_')) )

            ret.Append(c);
        else if (c == _T(' '))
            ret.Append(_T('+'));
        else
        {
            t.sprintf(_T("%%%02X"), (unsigned int) c);
            ret.Append(t);
        }
    }
    return ret;
}

What does this encoding stand for? As far as i know in URL Encoding the " " gets "%20" and not "+" like in this encoding...

greetings
Title: Re: What does "URLEncode" stand for?
Post by: oBFusCATed on February 03, 2015, 01:03:35 am
It just converts the character to two hex numbers. I think. Space is 32==20 in hex.
Title: Re: What does "URLEncode" stand for?
Post by: BlueHazzard on February 03, 2015, 01:09:37 am
then the current implementation is wrong:
see line
Code
else if (c == _T(' '))
            ret.Append(_T('+'));
Title: Re: What does "URLEncode" stand for?
Post by: Alpha on February 03, 2015, 03:29:45 am
As far as i know in URL Encoding the " " gets "%20" and not "+" like in this encoding...
According to this (http://www.w3schools.com/tags/ref_urlencode.asp), both "%20" and "+" are valid alternatives.