From d62c6d96e31ea5bdfa7c8f159b67cbfefef3cf43 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Fri, 29 Apr 2022 15:50:41 -0700 Subject: [PATCH] [import matcher] Only append description if there's something to append to. Otherwise just set the new string. --- gnucash/import-export/import-backend.c | 34 +++++++++++++++----------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/gnucash/import-export/import-backend.c b/gnucash/import-export/import-backend.c index 60a79077e6..8b796ab94c 100644 --- a/gnucash/import-export/import-backend.c +++ b/gnucash/import-export/import-backend.c @@ -841,25 +841,21 @@ void split_find_match (GNCImportTransInfo * trans_info, /* append the imported transaction description to the matched transaction description */ static void -desc_append (Transaction* selected_match_trans, Transaction* imp_trans) +desc_append (Transaction* selected_match_trans, gchar *new_desc) { - gchar* tmp = g_strconcat( xaccTransGetDescription (selected_match_trans), - "|", - xaccTransGetDescription (imp_trans), - NULL); + const gchar* curr_desc = xaccTransGetDescription (selected_match_trans); + gchar* tmp = g_strconcat(curr_desc, "|", new_desc, NULL); xaccTransSetDescription (selected_match_trans, tmp); g_free (tmp); } /* append the imported transaction notes to the matched transaction notes */ static void -notes_append (Transaction* selected_match_trans, Transaction* imp_trans) +notes_append (Transaction* selected_match_trans, gchar* new_notes) { - gchar* tmp = g_strconcat (xaccTransGetNotes (selected_match_trans), - "|", - xaccTransGetNotes (imp_trans), - NULL); - xaccTransSetNotes (selected_match_trans, tmp); + const gchar* curr_notes = xaccTransGetNotes (selected_match_trans); + gchar* tmp = g_strconcat (curr_notes, "|", new_notes, NULL); + xaccTransSetNotes (selected_match_trans, tmp ); g_free (tmp); } @@ -887,7 +883,7 @@ update_desc_and_notes (const GNCImportTransInfo* trans_info) note_imported = raw_str ? g_utf8_normalize (raw_str, -1, G_NORMALIZE_ALL) : NULL; raw_str = xaccTransGetNotes (selected_match->trans); - note_matched = + note_matched = raw_str ? g_utf8_normalize (raw_str, -1, G_NORMALIZE_ALL) : NULL; // Append if desc_imported not already in desc_matched @@ -895,14 +891,24 @@ update_desc_and_notes (const GNCImportTransInfo* trans_info) (!desc_matched || g_utf8_strlen (desc_imported, -1) > g_utf8_strlen (desc_matched, -1) || !strstr (desc_matched, desc_imported))) - desc_append (selected_match->trans, imp_trans); + { + if (desc_matched && *desc_matched) + desc_append (selected_match->trans, desc_imported); + else + xaccTransSetDescription (selected_match->trans, desc_imported); + } // Append if note_imported not already in note_matched if (note_imported && (!note_matched || g_utf8_strlen (note_imported, -1) > g_utf8_strlen (note_matched, -1) || !strstr (note_matched, note_imported))) - notes_append (selected_match->trans, imp_trans); + { + if (note_matched && *note_matched) + notes_append (selected_match->trans, note_imported); + else + xaccTransSetNotes (selected_match->trans, note_imported); + } g_free(desc_imported); g_free(desc_matched);