[devhelp] SearchContext: fix bug in match_link() when prefix appears several times



commit 485364f01d791dc315f5892c52a8c88fb6fc7eab
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Jan 21 15:31:49 2018 +0100

    SearchContext: fix bug in match_link() when prefix appears several times

 src/dh-search-context.c          |   21 +++++++--------------
 unit-tests/test-search-context.c |   12 ++++++++++++
 2 files changed, 19 insertions(+), 14 deletions(-)
---
diff --git a/src/dh-search-context.c b/src/dh-search-context.c
index 9fe970f..7a96bff 100644
--- a/src/dh-search-context.c
+++ b/src/dh-search-context.c
@@ -47,9 +47,8 @@ typedef struct _KeywordData {
 
         /* Created only if has_glob and is_first. */
         GPatternSpec *pattern_spec_prefix;
-        GPatternSpec *pattern_spec_nonprefix;
 
-        /* Created only if has_glob and !is_first. */
+        /* Created only if has_glob. */
         GPatternSpec *pattern_spec_anywhere;
 
         guint is_first : 1;
@@ -242,15 +241,11 @@ keyword_data_new (const gchar *keyword,
                         pattern = g_strdup_printf ("%s*", keyword);
                         data->pattern_spec_prefix = g_pattern_spec_new (pattern);
                         g_free (pattern);
-
-                        pattern = g_strdup_printf ("?*%s*", keyword);
-                        data->pattern_spec_nonprefix = g_pattern_spec_new (pattern);
-                        g_free (pattern);
-                } else {
-                        pattern = g_strdup_printf ("*%s*", keyword);
-                        data->pattern_spec_anywhere = g_pattern_spec_new (pattern);
-                        g_free (pattern);
                 }
+
+                pattern = g_strdup_printf ("*%s*", keyword);
+                data->pattern_spec_anywhere = g_pattern_spec_new (pattern);
+                g_free (pattern);
         }
 
         return data;
@@ -269,9 +264,6 @@ keyword_data_free (gpointer _data)
         if (data->pattern_spec_prefix != NULL)
                 g_pattern_spec_free (data->pattern_spec_prefix);
 
-        if (data->pattern_spec_nonprefix != NULL)
-                g_pattern_spec_free (data->pattern_spec_nonprefix);
-
         if (data->pattern_spec_anywhere != NULL)
                 g_pattern_spec_free (data->pattern_spec_anywhere);
 
@@ -484,7 +476,8 @@ _dh_search_context_match_link (DhSearchContext *search,
                                 if (prefix) {
                                         match = g_pattern_match_string (data->pattern_spec_prefix, 
link_name);
                                 } else {
-                                        match = g_pattern_match_string (data->pattern_spec_nonprefix, 
link_name);
+                                        match = (!g_pattern_match_string (data->pattern_spec_prefix, 
link_name) &&
+                                                 g_pattern_match_string (data->pattern_spec_anywhere, 
link_name));
                                 }
                         } else {
                                 if (prefix) {
diff --git a/unit-tests/test-search-context.c b/unit-tests/test-search-context.c
index 641f76c..69a15f3 100644
--- a/unit-tests/test-search-context.c
+++ b/unit-tests/test-search-context.c
@@ -258,6 +258,18 @@ test_link_simple (void)
         check_link_simple ("gtk*window*application", "gtk_window_get_application", FALSE, FALSE, FALSE);
         check_link_simple ("gtk*window*application", "GtkApplicationWindow", TRUE, FALSE, FALSE);
         check_link_simple ("gtk*window*application", "GtkApplicationWindow", FALSE, FALSE, FALSE);
+
+        /* Prefix appearing several times.
+         * The DhLink must not appear two times in the search results.
+         */
+        check_link_simple ("GTK CELL_RENDERER_ACCEL_MODE_GTK", "GTK_CELL_RENDERER_ACCEL_MODE_GTK",
+                           TRUE, TRUE, FALSE);
+        check_link_simple ("GTK CELL_RENDERER_ACCEL_MODE_GTK", "GTK_CELL_RENDERER_ACCEL_MODE_GTK",
+                           FALSE, FALSE, FALSE);
+        check_link_simple ("GTK* CELL_RENDERER_ACCEL_MODE_GTK", "GTK_CELL_RENDERER_ACCEL_MODE_GTK",
+                           TRUE, TRUE, FALSE);
+        check_link_simple ("GTK* CELL_RENDERER_ACCEL_MODE_GTK", "GTK_CELL_RENDERER_ACCEL_MODE_GTK",
+                           FALSE, FALSE, FALSE);
 }
 
 int


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]