Skip to content

Commit

Permalink
fix missing state return for types.params_shape
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Oct 17, 2023
1 parent 04b0d44 commit 0736b4f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lapis/validate/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ do
if errors then
return FailedTransform, errors
end
return out
return out, state
end
}
_base_0.__index = _base_0
Expand Down
2 changes: 1 addition & 1 deletion lapis/validate/types.moon
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class ParamsArrayType extends BaseType
if errors
return FailedTransform, errors

out
out, state

-- convert the array-like error message to a single string error messag
class FlattenErrors extends BaseType
Expand Down
24 changes: 24 additions & 0 deletions spec/validate_spec.moon
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,30 @@ params type {
}
}

it "captures state", ->
t = types.params_array types.partial({
title: types.string\tag "things[]"
}) + types.string\tag("things[]") / (o) -> {title: o}

res, state = assert t\transform {
{ title: "cool" }
{ title: "zone", age: 5 }
"whazt"
}

assert.same {
things: {
"cool", "zone", "whazt"
}
}, state

assert.same {
{ title: "cool" }
{ title: "zone", age: 5 }
{ title: "whazt"}
}, res


describe "flatten_errors", ->
types = require "lapis.validate.types"

Expand Down

0 comments on commit 0736b4f

Please sign in to comment.