TotalTechGeek / json-logic-engine

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

Resolve an issue with the unary operators. #32

Closed TotalTechGeek closed 1 month ago

TotalTechGeek commented 1 month ago

Resolved an issue with the built-in unary operators, where they did not account for whether the parameter was an array or not.

A note: There is still some incompatibility with if statements that do not have the required # of arguments.

Like these -

[
        {
            "if": []
        },
        null,
        null
    ],
    [
        {
            "if": [
                true
            ]
        },
        null,
        true
    ],
    [
        {
            "if": [
                false
            ]
        },
        null,
        false
    ],
    [
        {
            "if": [
                "apple"
            ]
        },
        null,
        "apple"
    ]

I'm not sure at this point in time if I agree with the original implementation that this should be the desired behavior. I'd really rather throw an exception for this. Maybe I could introduce a strict mode that has my preferences? Or allow permissive mode to behave like the original lib?

TotalTechGeek commented 1 month ago

This should fix issue #31