[libgweather/gnome-3-16] LocationEntry: fix database matching in the presence of whitespace



commit d9433617c7cd069d1f29993b34936a6fec843fe7
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Thu Apr 16 17:45:26 2015 -0700

    LocationEntry: fix database matching in the presence of whitespace
    
    Trailing whitespace should prevent prefix matches but not cause
    matching failures altoghether (trying to call find_word with
    a length of 0)

 libgweather/location-entry.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/libgweather/location-entry.c b/libgweather/location-entry.c
index d92d9dc..9994ea2 100644
--- a/libgweather/location-entry.c
+++ b/libgweather/location-entry.c
@@ -679,6 +679,9 @@ match_compare_name (const char *key, const char *name)
     gboolean is_first_word = TRUE;
     int len;
 
+    /* Ignore whitespace before the string */
+    key += strspn (key, " ");
+
     /* All but the last word in KEY must match a full word from NAME,
      * in order (but possibly skipping some words from NAME).
      */
@@ -699,7 +702,13 @@ match_compare_name (const char *key, const char *name)
     }
 
     /* The last word in KEY must match a prefix of a following word in NAME */
-    return find_word (name, key, strlen (key), FALSE, is_first_word) != NULL;
+    if (len == 0) {
+       return TRUE;
+    } else {
+       // if we get here, key[len] == 0, so...
+       g_assert (len == strlen(key));
+       return find_word (name, key, len, FALSE, is_first_word) != NULL;
+    }
 }
 
 static gboolean


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