Skip to content

The "all" operation will fail if data is an empty map when using variables. #42

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

Merged
merged 2 commits into from
Mar 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public Object evaluate(JsonLogicEvaluator evaluator, JsonLogicArray arguments, O

Object maybeArray = evaluator.evaluate(arguments.get(0), data);

if (maybeArray == null) {
return false;
}

if (!ArrayLike.isEligible(maybeArray)) {
throw new JsonLogicEvaluationException("first argument to all must be a valid array");
}
Expand Down
114 changes: 114 additions & 0 deletions src/test/resources/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -3711,5 +3711,119 @@
"items": []
},
false
],
[
{
"all": [
{
"var": ""
},
{
"in": [
{
"var": ""
},
["item1","item2","item3"]
]
}
]
},
[],
false
],
[
{
"all": [
{
"var": ""
},
{
"in": [
{
"var": ""
},
["item1","item2","item3"]
]
}
]
},
["item1"],
true
],
[
{
"all": [
{
"var": ""
},
{
"in": [
{
"var": ""
},
["item1","item2","item3"]
]
}
]
},
["item4"],
false
],
[
{
"all": [
{
"var": "item"
},
{
"in": [
{
"var": ""
},
["item1","item2","item3"]
]
}
]
},
{},
false
],
[
{
"all": [
{
"var": "item"
},
{
"in": [
{
"var": ""
},
["item1","item2","item3"]
]
}
]
},
{ "item": ["item1"] },
true
],
[
{
"all": [
{
"var": "item"
},
{
"in": [
{
"var": ""
},
["item1","item2","item3"]
]
}
]
},
{ "item": ["item4"] },
false
]
]