From c3c7afda0bd65a0333060addaf27331f6e414367 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 17 Aug 2023 20:29:30 +0100 Subject: add qs.lua --- qs.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 qs.lua (limited to 'qs.lua') diff --git a/qs.lua b/qs.lua new file mode 100644 index 0000000..fd1ed70 --- /dev/null +++ b/qs.lua @@ -0,0 +1,23 @@ +-- querystring and post body parsing + +local function urldecode(s) + return s:gsub('+',' ') + :gsub('%%(%x%x)',function(x) + return string.char(tonumber(x,16)) + end) +end + +local function parse_qs(s) + local ix = 1 + local res = {} + while true do + local _,next_ix,ek,ev = s:find("([^=]+)=([^&]*)&?",ix) + if not ek then break end + local k,v = urldecode(ek), urldecode(ev) + res[k] = v + ix = next_ix + 1 + end + return res +end + + -- cgit v1.2.3