Skip to content

Commit

Permalink
fix(schemas) strip string values
Browse files Browse the repository at this point in the history
Former-commit-id: 51641eff99e77ec56f69e0d2499f606ff461111c
  • Loading branch information
thibaultcha committed Jun 4, 2015
1 parent 880efe7 commit 0aa50e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions kong/dao/schemas_validation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function _M.validate(t, schema, is_update)

-- ALIASES: number, timestamp, boolean and array can be passed as strings and will be converted
if type(t[column]) == "string" then
t[column] = stringy.strip(t[column])
if v.type == "number" or v .type == constants.DATABASE_TYPES.TIMESTAMP then
t[column] = tonumber(t[column])
is_valid_type = t[column] ~= nil
Expand All @@ -66,6 +67,9 @@ function _M.validate(t, schema, is_update)
t[column] = bool == "true"
elseif v.type == "array" then
t[column] = stringy.split(t[column], ",")
for arr_k, arr_v in ipairs(t[column]) do
t[column][arr_k] = stringy.strip(arr_v)
end
is_valid_type = validate_type(v.type, t[column])
else -- if string
is_valid_type = validate_type(v.type, t[column])
Expand Down
3 changes: 2 additions & 1 deletion spec/unit/schemas_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ describe("Schemas", function()
it("should alias a string to `array`", function()
local s = { array = { type = "array" } }

local values = { array = "hello,world" }
-- It should also strip the resulting strings
local values = { array = "hello, world" }

local valid, err = validate(values, s)
assert.True(valid)
Expand Down

0 comments on commit 0aa50e0

Please sign in to comment.