[webkit-help] Question about FormData Encoding

John Terry john.m.terry9 at gmail.com
Tue Feb 2 00:27:28 PST 2010


Hi,

In FormDataBuilder, it has a method encodeStringAsFormData which transcode
the form data for form submission (e.g. replace ' ' with '+').
Can you please tell me if there is any code in Webkit which does the
opposite (e.g. convert '+' back to ' ')?

Thank you.

void FormDataBuilder::encodeStringAsFormData(Vector<char>& buffer, const
CString& string)
{
    static const char hexDigits[17] = "0123456789ABCDEF";

    // Same safe characters as Netscape for compatibility.
    static const char safeCharacters[] = "-._*";

    // http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1
    unsigned length = string.length();
    for (unsigned i = 0; i < length; ++i) {
        unsigned char c = string.data()[i];

        if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' &&
c <= '9') || strchr(safeCharacters, c))
            append(buffer, c);
        else if (c == ' ')
            append(buffer, '+');
        else if (c == '\n' || (c == '\r' && (i + 1 >= length ||
string.data()[i + 1] != '\n')))
            append(buffer, "%0D%0A");
        else if (c != '\r') {
            append(buffer, '%');
            append(buffer, hexDigits[c >> 4]);
            append(buffer, hexDigits[c & 0xF]);
        }
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-help/attachments/20100202/616fa409/attachment.html>


More information about the webkit-help mailing list