-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Description
When an if statement doesn't match on any of it's conditions, it returns all arguments instead of nil as expected:
JSONLogic.apply({ "if" => [false, 1] }, {}) # => [false, 1] (expected nil)
JSONLogic.apply({ "if" => [false, 1, false, 2] }, {}) # => [false, 1, false, 2] (expected nil)Background
if generally has the form [condition1, value1, condition2, value2, ...] and the first condition to be truthy returns the associated value, and if no conditions match null is returned.
{ "if": [false, 1] } // => null
{ "if": [false, 1, true, 2] } // => 2
{ "if": [false, 1, false, 2] } // => nullThere is a special case with an odd number of arguments [condition1, value1, condition2, value2, value_else] where the value_else is returned if none of the previous conditions match.
{ "if": [false, 1, 2] } // => 2
{ "if": [false, 1, false, 2, 3] } // => 3Metadata
Metadata
Assignees
Labels
No labels