gnucash maint: Bug 798679 - Unicode normalization should be used for comparison but not stored.

John Ralls jralls at code.gnucash.org
Wed Jan 4 16:25:31 EST 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/b922cfd7 (commit)
	from  https://github.com/Gnucash/gnucash/commit/797098c6 (commit)



commit b922cfd78dba20d92dbdf59b26d93039d66f395c
Author: John Ralls <jralls at ceridwen.us>
Date:   Wed Jan 4 13:19:36 2023 -0800

    Bug 798679 - Unicode normalization should be used for comparison but not stored.
    
    Change to NFC normalization for all comparisons because the Unicode
    meaning of compatible might collide with the user's intent.

diff --git a/gnucash/gnome-utils/gnc-tree-view-account.c b/gnucash/gnome-utils/gnc-tree-view-account.c
index b5b106f78..970214b6a 100644
--- a/gnucash/gnome-utils/gnc-tree-view-account.c
+++ b/gnucash/gnome-utils/gnc-tree-view-account.c
@@ -2828,7 +2828,7 @@ gboolean gnc_tree_view_search_compare (GtkTreeModel *model, gint column,
     gchar *case_normalized_key = NULL;
     gboolean match = FALSE;
 
-    normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
+    normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_NFC);
     if (normalized_key)
         case_normalized_key = g_utf8_casefold (normalized_key, -1);
     if (case_normalized_key)
@@ -2857,7 +2857,7 @@ gboolean gnc_tree_view_search_compare (GtkTreeModel *model, gint column,
             if (!str)
                 continue;
 
-            normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
+            normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_NFC);
             if (normalized_string)
                 case_normalized_string = g_utf8_casefold (normalized_string, -1);
             if (case_normalized_string&&NULL!=strstr(case_normalized_string,case_normalized_key))
diff --git a/gnucash/import-export/import-backend.c b/gnucash/import-export/import-backend.c
index b59018fa6..b88ab6b64 100644
--- a/gnucash/import-export/import-backend.c
+++ b/gnucash/import-export/import-backend.c
@@ -870,8 +870,8 @@ maybe_append_string (const char* match_string, const char* imp_string)
     if (!(imp_string && *imp_string))
         return retval;
 
-    norm_match_string = g_utf8_normalize (match_string, -1, G_NORMALIZE_ALL);
-    norm_imp_string = g_utf8_normalize (imp_string, -1, G_NORMALIZE_ALL);
+    norm_match_string = g_utf8_normalize (match_string, -1, G_NORMALIZE_NFC);
+    norm_imp_string = g_utf8_normalize (imp_string, -1, G_NORMALIZE_NFC);
 
     if (g_utf8_strlen (norm_imp_string, -1) > g_utf8_strlen (norm_match_string, -1) ||
          !strstr (norm_match_string, norm_imp_string))
diff --git a/gnucash/import-export/import-main-matcher.c b/gnucash/import-export/import-main-matcher.c
index ababddff6..75e92d3d7 100644
--- a/gnucash/import-export/import-main-matcher.c
+++ b/gnucash/import-export/import-main-matcher.c
@@ -986,7 +986,7 @@ static void populate_list (gpointer key, gpointer value, GtkListStore *list)
 {
     GtkTreeIter iter;
     const char *original = key;
-    char *normalized = g_utf8_normalize (original, -1, G_NORMALIZE_ALL);
+    char *normalized = g_utf8_normalize (original, -1, G_NORMALIZE_NFC);
     char *normalized_folded = normalized ? g_utf8_casefold (normalized, -1) : NULL;
     gtk_list_store_append (list, &iter);
     gtk_list_store_set (list, &iter,
diff --git a/gnucash/register/register-gnome/combocell-gnome.c b/gnucash/register/register-gnome/combocell-gnome.c
index 01abe784d..7dc0f7121 100644
--- a/gnucash/register/register-gnome/combocell-gnome.c
+++ b/gnucash/register/register-gnome/combocell-gnome.c
@@ -536,7 +536,7 @@ gnc_combo_cell_type_ahead_search (const gchar* newval,
     GRegex* regex0 = g_regex_new (escaped_sep, 0, 0, NULL);
     char* rep_str = g_regex_replace_literal (regex0, escaped_newval, -1, 0,
                                              newval_rep, 0, NULL);
-    char* normal_rep_str = g_utf8_normalize (rep_str, -1, G_NORMALIZE_ALL);
+    char* normal_rep_str = g_utf8_normalize (rep_str, -1, G_NORMALIZE_NFC);
     GRegex *regex = g_regex_new (normal_rep_str, G_REGEX_CASELESS, 0, NULL);
 
     gboolean valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (full_store),
@@ -565,7 +565,7 @@ gnc_combo_cell_type_ahead_search (const gchar* newval,
         gchar* normalized_str_data = NULL;
         gtk_tree_model_get (GTK_TREE_MODEL (full_store), &iter, 0,
                             &str_data, -1);
-        normalized_str_data = g_utf8_normalize (str_data, -1, G_NORMALIZE_ALL);
+        normalized_str_data = g_utf8_normalize (str_data, -1, G_NORMALIZE_NFC);
 
         if (g_regex_match (regex, normalized_str_data, 0, NULL))
         {
diff --git a/libgnucash/engine/qofutil.cpp b/libgnucash/engine/qofutil.cpp
index 846d7300f..f1bea733d 100644
--- a/libgnucash/engine/qofutil.cpp
+++ b/libgnucash/engine/qofutil.cpp
@@ -61,11 +61,11 @@ qof_utf8_substr_nocase (const gchar *haystack, const gchar *needle)
 
     haystack_casefold = g_utf8_casefold (haystack, -1);
     haystack_normalized = g_utf8_normalize (haystack_casefold, -1,
-                                            G_NORMALIZE_ALL);
+                                            G_NORMALIZE_NFC);
     g_free (haystack_casefold);
 
     needle_casefold = g_utf8_casefold (needle, -1);
-    needle_normalized = g_utf8_normalize (needle_casefold, -1, G_NORMALIZE_ALL);
+    needle_normalized = g_utf8_normalize (needle_casefold, -1, G_NORMALIZE_NFC);
     g_free (needle_casefold);
 
     p = strstr (haystack_normalized, needle_normalized);



Summary of changes:
 gnucash/gnome-utils/gnc-tree-view-account.c       | 4 ++--
 gnucash/import-export/import-backend.c            | 4 ++--
 gnucash/import-export/import-main-matcher.c       | 2 +-
 gnucash/register/register-gnome/combocell-gnome.c | 4 ++--
 libgnucash/engine/qofutil.cpp                     | 4 ++--
 5 files changed, 9 insertions(+), 9 deletions(-)



More information about the gnucash-changes mailing list