From a13184978a07e4c6735e5d5893076ffd8117c6a1 Mon Sep 17 00:00:00 2001 From: Christian Gruber Date: Mon, 27 Jan 2020 23:01:25 +0100 Subject: [PATCH] Fix calculation of token info to find exactly matching tokens only In get_first_pass_probabilities() function qof_instance_foreach_slot_prefix() is called with a prefix path including closing slash after token now. This avoids, that also entries with token as a substring are included in token info, where key only starts with token. Finally function build_token_info() checks, if the key suffix after the token consists only of the GUID. This avoids, that also entries with the same prefix and slashes are included in token info. --- libgnucash/engine/Account.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp index fee1187bc8..805daeea4e 100644 --- a/libgnucash/engine/Account.cpp +++ b/libgnucash/engine/Account.cpp @@ -5281,13 +5281,15 @@ struct AccountInfo static void build_token_info(char const * suffix, KvpValue * value, TokenAccountsInfo & tokenInfo) { - tokenInfo.total_count += value->get(); - AccountTokenCount this_account; - std::string account_guid {suffix}; - /*By convention, the key ends with the account GUID.*/ - this_account.account_guid = account_guid.substr(account_guid.size() - GUID_ENCODING_LENGTH); - this_account.token_count = value->get(); - tokenInfo.accounts.push_back(this_account); + if (strlen(suffix) == GUID_ENCODING_LENGTH) + { + tokenInfo.total_count += value->get(); + AccountTokenCount this_account; + /*By convention, the key ends with the account GUID.*/ + this_account.account_guid = std::string{suffix}; + this_account.token_count = value->get(); + tokenInfo.accounts.push_back(this_account); + } } /** We scale the probability values by probability_factor. @@ -5332,7 +5334,7 @@ get_first_pass_probabilities(GncImportMatchMap * imap, GList * tokens) for (auto current_token = tokens; current_token; current_token = current_token->next) { TokenAccountsInfo tokenInfo{}; - auto path = std::string{IMAP_FRAME_BAYES "/"} + static_cast (current_token->data); + auto path = std::string{IMAP_FRAME_BAYES "/"} + static_cast (current_token->data) + "/"; qof_instance_foreach_slot_prefix (QOF_INSTANCE (imap->acc), path, &build_token_info, tokenInfo); for (auto const & current_account_token : tokenInfo.accounts) {