News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

What does "URLEncode" stand for?

Started by BlueHazzard, February 03, 2015, 12:36:32 AM

Previous topic - Next topic

BlueHazzard

Hi, i try to write a test bench for the scripting binding, and found this function:

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

oBFusCATed

It just converts the character to two hex numbers. I think. Space is 32==20 in hex.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

BlueHazzard

then the current implementation is wrong:
see line
else if (c == _T(' '))
            ret.Append(_T('+'));

Alpha

Quote from: BlueHazzard on February 03, 2015, 12:36:32 AM
As far as i know in URL Encoding the " " gets "%20" and not "+" like in this encoding...
According to this, both "%20" and "+" are valid alternatives.