From aaae95ae682f621bd17965147126bf5cf73d2df2 Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 15 Aug 2022 16:51:41 -0500 Subject: add decode_query --- marigold.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'marigold.lua') 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 -- cgit v1.2.1