Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support dash in args (#4519) #4676

Merged
merged 19 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions apisix/core/ctx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ local setmetatable = setmetatable
local sub_str = string.sub
local ngx = ngx
local ngx_var = ngx.var
local ngx_re_match = ngx.re.match
local re_gsub = ngx.re.gsub
local ipairs = ipairs
local type = type
Expand Down Expand Up @@ -164,16 +163,15 @@ do
end
end

elseif core_str.has_prefix(key, "arg_") then
local args = t.args
local arg_key = sub_str(key, 5)
local m, err = ngx_re_match(args, "(^|&)" .. arg_key .. "=([^&]*)(&|$)", "jo")
if err then
log.warn("failed to fetch arg value by key: ",
key, " error: ", err)
end
if m then
val = m[2]
elseif core_str.has_prefix(key, "uri_args_") then
nanamikon marked this conversation as resolved.
Show resolved Hide resolved
local arg_key = sub_str(key, 10)
local args = ngx.req.get_uri_args()[arg_key]
nanamikon marked this conversation as resolved.
Show resolved Hide resolved
if args then
if type(args) == "table" then
val = args[1]
else
val = args
end
end

elseif core_str.has_prefix(key, "http_") then
Expand Down
8 changes: 4 additions & 4 deletions t/core/ctx2.t
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ balancer_port: 1980
local ctx = {}
core.ctx.set_vars_meta(ctx)

ngx.say("arg_a-b: ", ctx.var["arg_a-b"])
ngx.say("uri_args_a-b: ", ctx.var["uri_args_a-b"])
}
}
--- request
GET /t?a-b=aaa
--- response_body
arg_a-b: aaa
uri_args_a-b: aaa



Expand All @@ -165,10 +165,10 @@ arg_a-b: aaa
local ctx = {}
core.ctx.set_vars_meta(ctx)

ngx.say("arg_a-b: ", ctx.var["arg_a-b"])
ngx.say("uri_args_a-b: ", ctx.var["uri_args_a-b"])
}
}
--- request
GET /t?a-b=aaa&a-b=bbb
--- response_body
arg_a-b: aaa
uri_args_a-b: aaa