shared: end string with % if one was found at the end of a expandible string (#6828)
authorFelipe Sateler <fsateler@users.noreply.github.com>
Thu, 14 Sep 2017 17:51:20 +0000 (14:51 -0300)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 14 Sep 2017 17:51:19 +0000 (19:51 +0200)
Current behavior is that %X where X is an unidentified specifier, then the result is
the same %X string. This was not the case when the string ended with a stray %, where
the character would have not been output. Lets add that missing character.

Fixes: #6374

src/shared/specifier.c
src/test/test-unit-name.c

index 1c17eb5..8137904 100644 (file)
@@ -107,6 +107,10 @@ int specifier_printf(const char *text, const Specifier table[], void *userdata,
                         *(t++) = *f;
         }
 
+        /* if string ended with a stray %, also end with % */
+        if (percent)
+                *(t++) = '%';
+
         *t = 0;
         *_ret = ret;
         return 0;
index b8979c0..dcccc90 100644 (file)
@@ -237,7 +237,8 @@ static int test_unit_printf(void) {
         /* general tests */
         expect(u, "%%", "%");
         expect(u, "%%s", "%s");
-        expect(u, "%", "");    // REALLY?
+        expect(u, "%,", "%,");
+        expect(u, "%", "%");
 
         /* normal unit */
         expect(u, "%n", "blah.service");