diff options
author | Richard Hughes <richard@hughsie.com> | 2016-08-04 15:07:55 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2016-08-04 15:07:55 +0100 |
commit | 86ebfd1d4b94f626a2d5aeb3843b5c551e06447d (patch) | |
tree | 73983f62b552b163b45539a6d2654e619faf143c | |
parent | a188d7b35f44105a307c6df75825a755ffa413a7 (diff) | |
download | appstream-glib-86ebfd1d4b94f626a2d5aeb3843b5c551e06447d.tar.gz |
trivial: Fix as_utils_unique_id_equal() to work with multiple globs
-rw-r--r-- | libappstream-glib/as-self-test.c | 4 | ||||
-rw-r--r-- | libappstream-glib/as-utils.c | 24 |
2 files changed, 17 insertions, 11 deletions
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c index 8515211..7aefaac 100644 --- a/libappstream-glib/as-self-test.c +++ b/libappstream-glib/as-self-test.c @@ -5037,7 +5037,9 @@ as_test_utils_unique_id_func (void) g_assert (as_utils_unique_id_equal ("user/flatpak/utopia/desktop/gimp.desktop/i386/master/1.2.3", "*/*/*/*/*/*/*/*")); g_assert (!as_utils_unique_id_equal ("zz/zz/zz/zz/zz/zz/zz/zz", - "aa/bb/cc/dd/ee/ff/gg/hh")); + "aa/bb/cc/dd/ee/ff/gg/hh")); + g_assert (!as_utils_unique_id_equal ("user/*/*/shell-extension/gmail_notify@jablona123.pl.shell-extension/*/*/*", + "*/*/*/desktop/org.gnome.accerciser.desktop/*/*/*")); } duration_ns = g_timer_elapsed (timer, NULL) * 1000000000.f; g_print ("%.0f ns: ", duration_ns / (loops * 4)); diff --git a/libappstream-glib/as-utils.c b/libappstream-glib/as-utils.c index 7b6b0e3..80633d6 100644 --- a/libappstream-glib/as-utils.c +++ b/libappstream-glib/as-utils.c @@ -1797,6 +1797,12 @@ as_utils_unique_id_valid (const gchar *unique_id) return sections == 8; } +static inline gboolean +as_utils_unique_id_is_wildcard_part (const gchar *str, guint len) +{ + return len == 1 && str[0] == '*'; +} + /** * as_utils_unique_id_equal: * @unique_id1: a unique ID @@ -1836,16 +1842,14 @@ as_utils_unique_id_equal (const gchar *unique_id1, const gchar *unique_id2) len2 = as_utils_unique_id_find_part (tmp2); /* either string was a wildcard */ - if (len1 == 1 && tmp1[0] == '*') - continue; - if (len2 == 1 && tmp2[0] == '*') - continue; - - /* are substrings the same */ - if (len1 != len2) - return FALSE; - if (memcmp (tmp1, tmp2, len1) != 0) - return FALSE; + if (!as_utils_unique_id_is_wildcard_part (tmp1, len1) && + !as_utils_unique_id_is_wildcard_part (tmp2, len2)) { + /* are substrings the same */ + if (len1 != len2) + return FALSE; + if (memcmp (tmp1, tmp2, len1) != 0) + return FALSE; + } /* advance to next section */ last1 += len1 + 1; |