URL encoding is an encoding used by HTTP to transmit various parameters at a single URL clock. This encoding will encode special characters (such as ' = ', ' & ', ' + ') in the form of '%<xx> ', where <xx> is the hexadecimal representation of the character. In addition, it converts spaces to "+". For example, it encodes the string "A+b=c" as "A%2bb+%3d+c". Finally, it joins each pair of parameter names and their values with "=" and connects each pair of results Name=value with "&". For example, for values:
Name = "A1"; query = "A+b = C"; Q= "Yes or no"
will be encoded as:
"Name=a1&query=a%2bb+%3d+c&q=yes+or+no"
Now, to decode this URL, you need to save each value in the encoding, and its name as a key, in a table. Once the function completes the basic code:
function unescape (s) s = string.gsub (S, "+", "") s = string.gsub (s), "percent (%x%x)", function (h) return string. char (Tonumber (H, +)) end) return S end
Use Gmatch to decode the name=value. Because both the name and the value cannot contain "&" and "=", you can use the pattern "[^&=]+" to match them:
cgi = {}function decode (s) for name, value in String.gmatch (S, "([^&=]+] = ([^&=]+)") Do name = Unescape ( Name) value = unescape (value) cgi[name] = value EndEnd
Excerpt from chapter 20th of the second edition of LUA programming-20.5 replacing -20.5.1URL encoding
Openresty How to decode a URL