bhgames / json-logic-ruby

Build complex rules, serialize them as JSON, and execute them in ruby
MIT License
69 stars 33 forks source link

`in` operator doesn't work correctly with `var` #11

Closed l4cr0ss closed 5 years ago

l4cr0ss commented 5 years ago

I believe this is a bug, but please tell me if it's just my expectation that needs to be corrected:

irb(main):028:0> data = {"code": "45736123"}
=> {:code=>"45736123"}
irb(main):029:0> rule = {"in": ["123",{"var": "code"}]}
=> {:in=>["123", {:var=>"code"}]}
irb(main):030:0> JSONLogic.apply(rule,data)
=> false

Works fine when hardcoded:

irb(main):031:0> rule = {"in": ["123","45736123"]}
=> {:in=>["123", "45736123"]}
irb(main):032:0> JSONLogic.apply(rule,data)
=> true
irb(main):033:0> JSONLogic.apply(rule,nil)
=> true
l4cr0ss commented 5 years ago

I used the testing playground at http://jsonlogic.com/play.html and the first example I posted works fine there, making me believe further that yes, this is a bug.

l4cr0ss commented 5 years ago

bump

l4cr0ss commented 5 years ago

I am happy to take a look into what would be needed to fix this, but before I do I'd like to know that a reasonable pull request will be accepted. Please let me know.

l4cr0ss commented 5 years ago

bump

bhgames commented 5 years ago

Hey just got this

bhgames commented 5 years ago

Yeah I need to adjust ntoification settings on this repo

bhgames commented 5 years ago

@l4cr0ss Thanks for contacting us on this. It does indeed look to be a bug. As far as submitting a PR goes, you just need to fix the code and introduce a test to make sure it stays fixed. Nothing fancy here, this is not a highly used repository.

mjuszczak commented 5 years ago

Has there been any update to this? @bhgames @l4cr0ss

bhgames commented 5 years ago

Not since I last replied to him. I would be happy to accept a PR from you @mjuszczak, if you're interested!

mjuszczak commented 5 years ago

@bhgames We wrote a test and @eropple from our team satisfied it. Can you review the PR?

bhgames commented 5 years ago

Reviewing.

bhgames commented 5 years ago

Soon to be resolved by https://github.com/bhgames/json-logic-ruby/pull/13