From 975f51c829950ee78d2866b4b140d1a63c80c0bb Mon Sep 17 00:00:00 2001 From: Niko Raes Date: Wed, 16 Oct 2024 11:52:00 +0200 Subject: [PATCH] Improvements and additional tests --- JexlNet.ExtendedGrammar/ExtendedGrammar.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/JexlNet.ExtendedGrammar/ExtendedGrammar.cs b/JexlNet.ExtendedGrammar/ExtendedGrammar.cs index 47af043..78a2364 100644 --- a/JexlNet.ExtendedGrammar/ExtendedGrammar.cs +++ b/JexlNet.ExtendedGrammar/ExtendedGrammar.cs @@ -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]; } @@ -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() @@ -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(); }