summaryrefslogtreecommitdiff
path: root/marigold.lua
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-08-15 16:51:41 -0500
committersanine <sanine.not@pm.me>2022-08-15 16:51:41 -0500
commitaaae95ae682f621bd17965147126bf5cf73d2df2 (patch)
treeb7c1369c3d42c6c572ace6cfff8e591aff69c902 /marigold.lua
parent819d1ebb624c946f383bcea54f6b4363a1fa0153 (diff)
add decode_query
Diffstat (limited to 'marigold.lua')
-rw-r--r--marigold.lua16
1 files changed, 15 insertions, 1 deletions
diff --git a/marigold.lua b/marigold.lua
index 02c9bbe..c01eecd 100644
--- a/marigold.lua
+++ b/marigold.lua
@@ -121,11 +121,25 @@ marigold.html = function(tbl, indent_level)
indent, close)
end
-marigold.percentDecode = function(str)
+marigold.decode_percent = function(str)
return string.gsub(str, "%%(%x%x)", function(digits)
return string.char(tonumber(digits, 16))
end)
end
+marigold.decode_query = function(str)
+ local tbl = {}
+ local cleanString = function(str)
+ return marigold.decode_percent(
+ string.gsub(str, "+", " ")
+ )
+ end
+
+ for k, v in string.gmatch(str, "([^=]-)=([^&]*)&?") do
+ tbl[cleanString(k)] = cleanString(v)
+ end
+
+ return tbl
+end
return marigold