From 94c614a29665950e707702bd348dce97ac28d250 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 27 Mar 2018 21:47:58 -0300 Subject: [PATCH] fix(admin) do not mutate plugins schema in /plugins/schema/:name Make `remove_functions` produce a copy instead of modifying the plugin schema table in-place. Fix #3222 From #3348 --- kong/api/routes/plugins.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/kong/api/routes/plugins.lua b/kong/api/routes/plugins.lua index 9d6e97ab5ca2..c2b63d2cd399 100644 --- a/kong/api/routes/plugins.lua +++ b/kong/api/routes/plugins.lua @@ -7,14 +7,13 @@ local singletons = require "kong.singletons" -- Remove functions from a schema definition so that -- cjson can encode the schema. local function remove_functions(schema) + local copy = {} for k, v in pairs(schema) do - if type(v) == "function" then - schema[k] = "function" - end - if type(v) == "table" then - remove_functions(schema[k]) - end + copy[k] = (type(v) == "function" and "function") + or (type(v) == "table" and remove_functions(schema[k])) + or v end + return copy end return { @@ -50,9 +49,9 @@ return { return helpers.responses.send_HTTP_NOT_FOUND("No plugin named '" .. self.params.name .. "'") end - remove_functions(plugin_schema) + local copy = remove_functions(plugin_schema) - return helpers.responses.send_HTTP_OK(plugin_schema) + return helpers.responses.send_HTTP_OK(copy) end },