Skip to content

Commit

Permalink
Improvements and additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikoraes committed Oct 16, 2024
1 parent d34fc73 commit 975f51c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions JexlNet.ExtendedGrammar/ExtendedGrammar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ public static JsonNode Case(JsonNode[] args)
}
}
// Return default
if (args.Length % 2 == 1)
if (args.Length % 2 == 0)
{
return args[args.Length - 1];
}
Expand Down Expand Up @@ -1464,7 +1464,7 @@ public static JsonNode ArrayFind(JsonNode input, JsonNode expression)
if (input is JsonArray array && expression is JsonValue exprVal)
{
Jexl jexl = new Jexl(new ExtendedGrammar());
Expression jExpression = jexl.CreateExpression(exprVal.ToString());
Expression jexlExpression = jexl.CreateExpression(exprVal.ToString());
for (int i = 0; i < array.Count; i++)
{
var context = new JsonObject()
Expand All @@ -1473,7 +1473,7 @@ public static JsonNode ArrayFind(JsonNode input, JsonNode expression)
["index"] = i,
["array"] = array.DeepClone(),
};
if (jExpression.Eval(context)?.AsValue().ToBoolean() ?? false)
if (jexlExpression.Eval(context) is JsonValue jsonValue && jsonValue.GetValueKind() == JsonValueKind.True)
{
return array[i]?.DeepClone();
}
Expand Down

0 comments on commit 975f51c

Please sign in to comment.