diff options
author | Giovanni Campagna <gcampagna@src.gnome.org> | 2015-04-16 17:45:26 -0700 |
---|---|---|
committer | Giovanni Campagna <gcampagna@src.gnome.org> | 2015-04-16 17:48:29 -0700 |
commit | d9433617c7cd069d1f29993b34936a6fec843fe7 (patch) | |
tree | 9609f93931bb5fef30d45d63542fc98a82371a57 | |
parent | 32df6a2579ef5ee48be1603e3b930b6f0bf1fe6a (diff) | |
download | libgweather-d9433617c7cd069d1f29993b34936a6fec843fe7.tar.gz |
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)
-rw-r--r-- | 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 |