bastikr / boolean.py

Implements boolean algebra in one module.
BSD 2-Clause "Simplified" License
78 stars 34 forks source link

Fails to detect repeated operators in a single expression (e.g. a &&& b) #61

Open ItsAshleyJ182 opened 7 years ago

ItsAshleyJ182 commented 7 years ago

Parsing search strings such as 'a &&& b' or even 'a & & b' generates a result of AND( Symbol('a'), Symbol('yes') ) When realistically, neither expression makes that much sense syntactically. Looking at the code, there only seems to be checking for repeated Symbol objects. Is this a design decision that was made during development? I see this leading to potential instances where a user would send in an incorrect search string that evaluates to an unintended result.

pombredanne commented 7 years ago

@banjoanderson this is eventually a bug. Fixes welcomed if you feel like it.

pombredanne commented 7 years ago

One approach to resolve this would be to iterate on the tokenize() results https://github.com/bastikr/boolean.py/blob/6ff13163c1360574534913d15a3b0bee2660c26a/boolean/boolean.py#L359 at the start of parse() https://github.com/bastikr/boolean.py/blob/6ff13163c1360574534913d15a3b0bee2660c26a/boolean/boolean.py#L179 eventually in another function and raise ParseError for illegal token sub-sequences such as repeated & and likely a few other cases

pombredanne commented 7 years ago

And btw, sorry for the late reply to your ticket! and thank you for using boolean.py!