TotalTechGeek / json-logic-engine

Construct complex rules with JSON & process them.
MIT License
43 stars 9 forks source link

Invert operator broken for longhand version #31

Closed toddbaert closed 1 month ago

toddbaert commented 1 month ago

As per the examples in the JsonLogic site, unary operators should accept an array with a single argument (longhand), or a shorthand version where the array is omitted and just the argument is passed. Unfortunately, the longhand doesn't seem to work in this implementation:

{
    "!": false
}

This returns true (inversion working as expected) :+1:

{
    "!": [
        false
    ]
}

This returns false (inversion not working) :-1:

Please note that this isn't a question of type coercion. The argument being passed in the second case is not the array itself, it's the first element in the array (the false) as in other operations. This bug may impact other operators. I have not tested further.

The JsonLogic website examples make this clear: https://jsonlogic.com/operations.html#logic-and-boolean-operations

image

TotalTechGeek commented 1 month ago

Hey @toddbaert ; good catch, will take a look ASAP.

Will see if I can get this fixed in the half-hour

toddbaert commented 1 month ago

:pray: Thanks for the support! Let me know if I can help.

TotalTechGeek commented 1 month ago

Release 1.3.3 should be available now! :)

toddbaert commented 1 month ago

It's available and I can confirm the issue is resolved with 1.3.3. Thanks again!