json-logic-ruby icon indicating copy to clipboard operation
json-logic-ruby copied to clipboard

"IN" Operator Fails When Accessed via "VAR" Operator

Open imanrahmani opened this issue 9 months ago • 0 comments

Problem Statement:

While trying to access a subset array from within a superset array using the "All" operator, I found that the "IN" operator does not function correctly when an array is accessed via the "VAR" operator.

Observed Behavior: In the rule example below, the "IN" operator fails to correctly validate if all elements of the subset array are contained within the superset array:

Rule:

{ "all": [ {"var": "subset"}, {"in": [{"var": ""}, {"var": "superset"}]} ] } Data

{ "subset": ["apple", "banana", "orange"], "superset": ["apple", "banana", "orange", "grape", "pear"] }

Expected Outcome: The evaluation of this rule should yield True, as the subset array is fully included in the superset array.

Actual Outcome: The rule incorrectly returns False.

Hint / Workaround: When I specify the array directly within the rule instead of referencing it with the "VAR" operator, the "IN" operator behaves as expected:

Working Rule: { "all": [ {"var": "subset"}, {"in": [{"var": ""}, ["apple", "banana", "orange", "grape", "pear"]]} ] }

I suspect there might be a bug in the way the "IN" operator processes references to arrays. Your assistance in identifying and resolving the root cause of this behavior would be greatly appreciated.

imanrahmani avatar May 07 '24 10:05 imanrahmani