basic: pass flags to the fnmatch (#3606)
authorEvgeny Vereshchagin <evvers@ya.ru>
Mon, 27 Jun 2016 12:47:37 +0000 (15:47 +0300)
committerMartin Pitt <martin.pitt@ubuntu.com>
Mon, 27 Jun 2016 12:47:37 +0000 (14:47 +0200)
Fixes:
```
$ systemctl list-unit-files 'hey\*'

0 unit files listed.

$ systemctl list-unit-files | grep hey
hey\x7eho.service                          static
```

src/basic/strv.c
src/test/test-strv.c

index 578a9c1..4e81534 100644 (file)
@@ -834,7 +834,7 @@ bool strv_fnmatch(char* const* patterns, const char *s, int flags) {
         char* const* p;
 
         STRV_FOREACH(p, patterns)
-                if (fnmatch(*p, s, 0) == 0)
+                if (fnmatch(*p, s, flags) == 0)
                         return true;
 
         return false;
index fc01dcf..cf5887d 100644 (file)
@@ -685,6 +685,16 @@ static void test_foreach_string(void) {
                 assert_se(streq(x, "zzz"));
 }
 
+static void test_strv_fnmatch(void) {
+        _cleanup_free_ char **v = NULL;
+
+        assert_se(!strv_fnmatch(STRV_MAKE_EMPTY, "a", 0));
+
+        v = strv_new("*\\*", NULL);
+        assert_se(!strv_fnmatch(v, "\\", 0));
+        assert_se(strv_fnmatch(v, "\\", FNM_NOESCAPE));
+}
+
 int main(int argc, char *argv[]) {
         test_specifier_printf();
         test_strv_foreach();
@@ -750,6 +760,7 @@ int main(int argc, char *argv[]) {
         test_strv_make_nulstr();
 
         test_foreach_string();
+        test_strv_fnmatch();
 
         return 0;
 }