Skip to content
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

IN operator fails when nil is passed as the array to search in #28

Open
GonzaRodriguez opened this issue Jun 28, 2022 · 1 comment
Open

Comments

@GonzaRodriguez
Copy link

I've noticed that the in operator is failing when receiving nil values as the array.

Context:

We have been using JSONLogic for a couple of years now to evaluate rules on serialized objects at runtime. Most of the time, we don't know the actual values of the variables used in the rules since they are built by serializing objects retrieved from our database.

Current behavior:

When the variable (array to search in) doesn't exist in the object, a nil value is passed as the array, so in that case the gem is failing due to a NoMethodError: undefined method include?' for nil:NilClass`.

Here you can see an example:

rule = {"in" => ["value_to_search", {"var" => "array"}]}
variable = {"array" => nil} (Consider that nil is the value after some processing at runtime)

JSONLogic.apply(rule, variable)

The output:

Screen Shot 2022-06-28 at 19 11 21

@GonzaRodriguez
Copy link
Author

GonzaRodriguez commented Jun 28, 2022

@bhgames I will be pleased to open a PR to fix it. Please let me know if it makes sense for you.

GonzaRodriguez added a commit to Backlot-Cars/json-logic-ruby that referenced this issue Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant