Table of Contents

About

Unescapes the keys and values of a key-value data string and making them compliant with RFC1738.

In other words, wasKeyValueURLUnescape will take as input a percent-encoded string of keys and values and return an unescaped string of keys and values. This is useful in order to be able to decode URL-encoded strings.

Example Usage

When called with:

string data = "hello%21=there&how=are+you";
wasKeyValueURLUnescape($data);

the function will return the string:

hello!=there&how=are you

Code

LSL

///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0    //
///////////////////////////////////////////////////////////////////////////
// unescapes a string in conformance with RFC1738
string wasURLUnescape(string i) {
    return llUnescapeURL(
        llDumpList2String(
            llParseString2List(
                llDumpList2String(
                    llParseString2List(
                        i, 
                        ["+"], 
                        []
                    ), 
                    " "
                ), 
                ["%0D%0A"], 
                []
            ), 
            "\n"
        )
    );
}
 
///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2014 Wizardry and Steamworks - License: CC BY 2.0    //
///////////////////////////////////////////////////////////////////////////
string wasKeyValueURLUnescape(string data) {
    list i = llParseString2List(data, ["&", "="], []);
    list output = [];
    do {
        output += wasURLUnescape(llList2String(i, 0)) + "=" + 
            wasURLUnescape(llList2String(i, 1));
        i = llDeleteSubList(i, 0, 1);
    } while(llGetListLength(i) != 0);
    return llDumpList2String(output, "&");
}