From 69ceed35f64c20f00f3daa7d33adf1219c8bb9fd Mon Sep 17 00:00:00 2001 From: Tyler Schicke Date: Thu, 21 Dec 2023 15:18:27 -0500 Subject: [PATCH] Make currency regex not incorrectly match substrings This changes the currency regexes use '^$' instead of just matching '', so that specifying a currency only matches that currency exactly, instead of also matching currencies that contain the specified currency. --- fava_investor/modules/cashdrag/libcashdrag.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fava_investor/modules/cashdrag/libcashdrag.py b/fava_investor/modules/cashdrag/libcashdrag.py index 7a541fe..f0f618f 100644 --- a/fava_investor/modules/cashdrag/libcashdrag.py +++ b/fava_investor/modules/cashdrag/libcashdrag.py @@ -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]