Skip to content

Commit

Permalink
Fix danthedeckie#51 (or should return falsy last value)
Browse files Browse the repository at this point in the history
 (+ (C) bump year and add contributors)
  • Loading branch information
danthedeckie authored Apr 7, 2019
1 parent 8d3d848 commit 164ee88
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions simpleeval.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
SimpleEval - (C) 2013-2018 Daniel Fairhead
SimpleEval - (C) 2013-2019 Daniel Fairhead
-------------------------------------
An short, easy to use, safe and reasonably extensible expression evaluator.
Expand Down Expand Up @@ -49,7 +49,8 @@
- mommothazaz123 (Andrew Zhu) f"string" support
- lubieowoce (Uryga) various potential vulnerabilities
- JCavallo (Jean Cavallo) names dict shouldn't be modified
- Birne94 (Daniel Birnstiel) for fixing leaking generators.
- patricksurry (Patrick Surry) or should return last value, even if falsy.
-------------------------------------
Basic Usage:
Expand Down Expand Up @@ -373,7 +374,7 @@ def _eval_boolop(self, node):
vout = self._eval(value)
if vout:
return vout
return False
return vout

def _eval_compare(self, node):
right = self._eval(node.left)
Expand Down
2 changes: 2 additions & 0 deletions test_simpleeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def test_bools_and_or(self):
self.t('110 != 100 + 10 and True', False)
self.t('False or 42', 42)

self.t('False or None', None)

self.s.names = {'out': True, 'position': 3}
self.t('(out and position <=6 and -10)'
' or (out and position > 6 and -5)'
Expand Down

0 comments on commit 164ee88

Please sign in to comment.