Created
April 11, 2013 16:57
-
-
Save solso/5365140 to your computer and use it in GitHub Desktop.
extract nested params on query_string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_query_args_extended() | |
args = ngx.req.get_query_args() | |
for k, v in pairs(args) do | |
t = {} | |
for k2 in string.gmatch(k, "%b[]") do | |
table.insert(t,string.sub(k2,2,string.len(k2)-1)) | |
end | |
if #t > 0 then | |
-- it has nested params, needs to be transformed | |
first = string.sub(k,1,string.find(k,"%[")-1) | |
if args[first]==nil or type(args[first])~="table" then | |
args[first] = {} | |
end | |
args[first][t[1]] = v | |
end | |
end | |
return args | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment