48 lines
1.7 KiB
Diff
48 lines
1.7 KiB
Diff
From 3d4e63e3655bb1464f73a2ee11571d4bd1355cda Mon Sep 17 00:00:00 2001
|
|
From: Felipe Sateler <fsateler@users.noreply.github.com>
|
|
Date: Thu, 14 Sep 2017 14:51:20 -0300
|
|
Subject: [PATCH] shared: end string with % if one was found at the end of a
|
|
expandible string (#6828)
|
|
|
|
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
|
|
(cherry picked from commit 038492aed3e0293fd9cf4998fd891addb597b954)
|
|
(cherry picked from commit 760a486ff45797b65093c5f0550cc42bfd5d70aa)
|
|
---
|
|
src/shared/specifier.c | 4 ++++
|
|
src/test/test-unit-name.c | 3 ++-
|
|
2 files changed, 6 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/src/shared/specifier.c b/src/shared/specifier.c
|
|
index 1c17eb5251..81379041cc 100644
|
|
--- a/src/shared/specifier.c
|
|
+++ b/src/shared/specifier.c
|
|
@@ -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;
|
|
diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c
|
|
index 2fd83f321c..2af90c69ee 100644
|
|
--- a/src/test/test-unit-name.c
|
|
+++ b/src/test/test-unit-name.c
|
|
@@ -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");
|