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

fix(schema-validator) does not convert the null in the declarative configuration to nil #8483

Merged
merged 9 commits into from
Mar 10, 2022
11 changes: 9 additions & 2 deletions kong/db/schema/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1578,8 +1578,15 @@ local function adjust_field_for_context(field, value, context, nulls, opts)
end

if subfield then
for i = 1, #value do
value[i] = adjust_field_for_context(subfield, value[i], context, nulls, opts)
if field.type ~= "map" then
for i = 1, #value do
value[i] = adjust_field_for_context(subfield, value[i], context, nulls, opts)
end

else
for k, v in pairs(value) do
value[k] = adjust_field_for_context(subfield, v, context, nulls, opts)
end
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/03-plugins/24-response-rate-limiting/01-schema_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local schema_def = require "kong.plugins.response-ratelimiting.schema"
local v = require("spec.helpers").validate_plugin_config_schema
local null = ngx.null


describe("Plugin: response-rate-limiting (schema)", function()
Expand Down Expand Up @@ -32,6 +33,12 @@ describe("Plugin: response-rate-limiting (schema)", function()
assert.falsy(ok)
assert.equal("unknown field", err.config.limits.seco)
end)
it("limits: \'null\' value does not cause 500, issue #8314", function()
local config = {limits = {video = {second = null, minute = 1}}}
local ok, err = v(config, schema_def)
assert.truthy(ok)
assert.falsy(err)
end)
it("limits: smaller unit is less than bigger unit", function()
local config = {limits = {video = {second = 2, minute = 1}}}
local ok, err = v(config, schema_def)
Expand Down