Skip to content

Commit

Permalink
Make currency regex not incorrectly match substrings
Browse files Browse the repository at this point in the history
This changes the currency regexes use '^<currency>$' instead of just
matching '<currency>', so that specifying a currency only matches that
currency exactly, instead of also matching currencies that contain the
specified currency.
  • Loading branch information
tschicke committed Dec 21, 2023
1 parent de79f65 commit 69ceed3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fava_investor/modules/cashdrag/libcashdrag.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def find_cash_commodities(accapi, options):
cash_commodities = []
for commodity, declaration in accapi.get_commodity_directives().items():
if declaration.meta.get(meta_label, 0) == 100:
cash_commodities.append(commodity)
cash_commodities.append(f'^{commodity}$')

operating_currencies = accapi.get_operating_currencies()
cash_commodities += operating_currencies
cash_commodities += map(lambda cur: f'^{cur}$', operating_currencies)
cash_commodities = set(cash_commodities)
commodities_pattern = '(' + '|'.join(cash_commodities) + ')'
return commodities_pattern, operating_currencies[0]
Expand Down

0 comments on commit 69ceed3

Please sign in to comment.