Skip to content

Commit

Permalink
fix(plugins): Request-Transformer rename behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlightIbuki committed Jul 10, 2024
1 parent 4664b90 commit c8d553b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/req-trans-rename.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**Request-Transformer**: Fixed an issue where renamed query parameters, url-encoded body parameters, and json body parameters were not handled properly when target name is the same as the source name in the request."
type: feature
scope: Plugin
22 changes: 14 additions & 8 deletions kong/plugins/request-transformer/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ local function transform_querystrings(conf, template_env)
-- Rename querystring(s)
for _, old_name, new_name in iter(conf.rename.querystring, template_env) do
local value = querystring[old_name]
querystring[new_name] = value
querystring[old_name] = nil
if value then
querystring[old_name] = nil
querystring[new_name] = value
end
end

for _, name, value in iter(conf.replace.querystring, template_env) do
Expand Down Expand Up @@ -276,9 +278,11 @@ local function transform_json_body(conf, body, content_length, template_env)
if content_length > 0 and #conf.rename.body > 0 then
for _, old_name, new_name in iter(conf.rename.body, template_env) do
local value = parameters[old_name]
parameters[new_name] = value
parameters[old_name] = nil
renamed = true
if value then
parameters[old_name] = nil
parameters[new_name] = value
renamed = true
end
end
end

Expand Down Expand Up @@ -327,9 +331,11 @@ local function transform_url_encoded_body(conf, body, content_length, template_e
if content_length > 0 and #conf.rename.body > 0 then
for _, old_name, new_name in iter(conf.rename.body, template_env) do
local value = parameters[old_name]
parameters[new_name] = value
parameters[old_name] = nil
renamed = true
if value then
parameters[old_name] = nil
parameters[new_name] = value
renamed = true
end
end
end

Expand Down

0 comments on commit c8d553b

Please sign in to comment.