diff options
author | ubq323 <ubq323@ubq323.website> | 2023-08-17 20:29:30 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-08-17 20:29:30 +0100 |
commit | c3c7afda0bd65a0333060addaf27331f6e414367 (patch) | |
tree | 2da74c9936843bc12a93fbdcf037173bd7e02b52 /qs.lua |
add qs.lua
Diffstat (limited to 'qs.lua')
-rw-r--r-- | qs.lua | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -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 + + |