zeroSteiner / rule-engine

A lightweight, optionally typed expression language with a custom grammar for matching arbitrary Python objects.
https://zerosteiner.github.io/rule-engine/
BSD 3-Clause "New" or "Revised" License
433 stars 54 forks source link

Bad behaviour with wrong rule that does not make errors and returns bad results #54

Closed Merlain closed 1 year ago

Merlain commented 1 year ago

Hello,

While writing rules, I realized the following result when I wrote "int_variable==01" instead of "int_variable==1".

When this condition is the only one in the rule, I get an error but when it is followed by other conditions, there is no more error and the returned results are invalid.

The results are invalid because what is before this condition does not seem to be taken into account.

Here is an example:

import rule_engine

data = {'other': 'other', 'test': 'test', 'count':1}

# Invalid rule that raise an error
rule_str = "count==01"
rule = rule_engine.Rule(rule_str) # Return an error

# Invalid rule that does not return an error
rule_str = "test=='NOTTEST' and count==01 and other=='other'"
rule = rule_engine.Rule(rule_str)

rule.matches(data) # True

In this case, the "test=='NOTTEST' " part is ignored because before the invalid condition (the invalid condition is also ignored).

zeroSteiner commented 1 year ago

Yeah, something is wrong here. I'm pretty sure it has to do with the 01 literal. I'm able to reproduce the unexpected behavior you're seeing and I've got what I need to look into this further.

Thanks for reporting this.

zeroSteiner commented 1 year ago

Fixed in commit 055dbfaeda51228223c16dc6bf54747524037dcf. I'll publish version 3.5.1 to PyPi with this fix this weekend.

Merlain commented 1 year ago

Thank you ! awsome !

zeroSteiner commented 1 year ago

Version 3.5.1 has been published to PyPi with this fix. https://pypi.org/project/rule-engine/3.5.1/