Skip to content

Commit

Permalink
Fix ArgumentException when var is used with in operator
Browse files Browse the repository at this point in the history
  • Loading branch information
XDex authored and yavuztor committed Aug 19, 2021
1 parent 25786cd commit 60484e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions JsonLogic.Net.UnitTests/JsonLogicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public JsonLogicTests(ITestOutputHelper output)
[InlineData("{`>`: [3, 4, 1]}", false)]
[InlineData("{`>=`: [3, 2, 1]}", true)]
[InlineData("{`>=`: [3, 1, 1]}", true)]
[InlineData("{`>=`: [3, 4, 1]}", false)]

[InlineData("{`>=`: [3, 4, 1]}", false)]

[InlineData("{`<`: [`2020-01-31`, `2020-02-01`, `2020-02-02`]}", true)]
[InlineData("{`<`: [`2020-01-31`, `2020-02-02`, `2020-02-02`]}", false)]
[InlineData("{`<`: [`2020-01-31`, `2020-02-03`, `2020-02-02`]}", false)]
Expand Down Expand Up @@ -148,6 +148,9 @@ public JsonLogicTests(ITestOutputHelper output)
[InlineData("{`in`: [`Spring`, `Springfield`]}", true)]
[InlineData("{`in`: [`Springs`, `Springfield`]}", false)]
[InlineData("{`in`: [`spring`, `Springfield`]}", false)]

[InlineData("{`in`:[`/homePage`,{`var`:`page.url`}]}", false)]

[InlineData("{`cat`: [`spring`, `field`]}", "springfield")]
[InlineData("{`substr`: [`springfield`, 6]}", "field")]
[InlineData("{`substr`: [`springfield`, 6, 3]}", "fie")]
Expand Down
1 change: 1 addition & 0 deletions JsonLogic.Net/EvaluateOperators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ private void AddDefaultOperations()
AddOperator("in", (p, args, data) => {
object needle = p.Apply(args[0], data);
object haystack = p.Apply(args[1], data);
if (haystack is null) return false;
if (haystack is String) return (haystack as string).IndexOf(needle.ToString()) >= 0;
return haystack.MakeEnumerable().Any(item => item.EqualTo(needle));
Expand Down

0 comments on commit 60484e5

Please sign in to comment.