You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2022/04/27 09:21:49 UTC
[apisix] branch master updated: chore: replace ngx.decode_args to core.string.decode_args (#6925)
This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new a06560ff3 chore: replace ngx.decode_args to core.string.decode_args (#6925)
a06560ff3 is described below
commit a06560ff359e1e0c49989ff44baf0f0083d5323b
Author: soulbird <zh...@outlook.com>
AuthorDate: Wed Apr 27 17:21:41 2022 +0800
chore: replace ngx.decode_args to core.string.decode_args (#6925)
---
apisix/core/string.lua | 30 ++++++++++++++++++++++++++++++
apisix/plugins/authz-keycloak.lua | 2 +-
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/apisix/core/string.lua b/apisix/core/string.lua
index a6a7359ff..5951d3378 100644
--- a/apisix/core/string.lua
+++ b/apisix/core/string.lua
@@ -27,6 +27,8 @@ local ffi = require("ffi")
local C = ffi.C
local ffi_cast = ffi.cast
local ngx = ngx
+local ngx_decode_args = ngx.decode_args
+local ngx_encode_args = ngx.encode_args
ffi.cdef[[
@@ -103,4 +105,32 @@ function _M.compress_script(s)
end
+---
+-- Decodes a URI encoded query-string into a Lua table.
+-- All request arguments received will be decoded by default.
+--
+-- @function core.string.decode_args
+-- @tparam string args A URI encoded query-string.
+-- @treturn table the value of decoded query-string.
+-- @usage
+-- local args, err = core.string.decode_args("a=1&b=2") -- {a=1, b=2}
+function _M.decode_args(args)
+ -- use 0 to avoid truncated result and keep the behavior as the
+ -- same as other platforms
+ return ngx_decode_args(args, 0)
+end
+
+
+---
+-- Encode the Lua table to a query args string according to the URI encoded rules.
+--
+-- @function core.string.encode_args
+-- @tparam table args The query args Lua table.
+-- @treturn string the value of query args string.
+-- @usage
+-- local str = core.string.encode_args({a=1, b=2}) -- "a=1&b=2"
+function _M.encode_args(args)
+ return ngx_encode_args(args)
+end
+
return _M
diff --git a/apisix/plugins/authz-keycloak.lua b/apisix/plugins/authz-keycloak.lua
index de316bafd..f792e1474 100644
--- a/apisix/plugins/authz-keycloak.lua
+++ b/apisix/plugins/authz-keycloak.lua
@@ -714,7 +714,7 @@ local function generate_token_using_password_grant(conf,ctx)
log.error("Failed to get request body: ", err)
return 503
end
- local parameters = ngx.decode_args(body)
+ local parameters = core.string.decode_args(body)
local username = parameters["username"]
local password = parameters["password"]