Author Topic: What does "URLEncode" stand for?  (Read 3610 times)

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
What does "URLEncode" stand for?
« 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

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: What does "URLEncode" stand for?
« Reply #1 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.
(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!]

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: What does "URLEncode" stand for?
« Reply #2 on: February 03, 2015, 01:09:37 am »
then the current implementation is wrong:
see line
Code
else if (c == _T(' '))
            ret.Append(_T('+'));

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: What does "URLEncode" stand for?
« Reply #3 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, both "%20" and "+" are valid alternatives.