Skip to content

Commit

Permalink
bugfix in filter_needs
Browse files Browse the repository at this point in the history
  • Loading branch information
big1hc committed Aug 10, 2023
1 parent c73c44f commit 3aaa39d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Released: under development
for debugging purposes.
(`#917 <https://github.com/useblocks/sphinx-needs/pull/917>`_)

* Bugfix: Check filter strings for correctness.
(`#964 <https://github.com/useblocks/sphinx-needs/pull/964>`_)
* Bugfix: Replace hardcoded `index` with config value `root_doc`.
(`#877 <https://github.com/useblocks/sphinx-needs/pull/877>`_)
* Bugfix: Fix unbounded memory usage in pickle environment.
Expand Down
9 changes: 7 additions & 2 deletions sphinx_needs/filter_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,14 @@ def filter_single_need(
# Set filter_context as globals and not only locals in eval()!
# Otherwise, the vars not be accessed in list comprehensions.
if filter_compiled:
result = bool(eval(filter_compiled, filter_context))
result = eval(filter_compiled, filter_context)
else:
result = bool(eval(filter_string, filter_context))
result = eval(filter_string, filter_context)
if result not in (True, False):
# Raises NeedsInvalidFilter if the result is not equal True/False
raise NeedsInvalidFilter(
f"Error when evaluating filter: expected output to have True/False but got a result <{result}>"
)
except Exception as e:
raise NeedsInvalidFilter(f"Filter {filter_string} not valid. Error: {e}.")
return result

0 comments on commit 3aaa39d

Please sign in to comment.