summaryrefslogtreecommitdiffstats
path: root/src/basic/escape.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-04-06 09:50:51 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-04-09 09:58:10 +0200
commit2b99f645c672efa239a6b8ab1ee2c084474cebba (patch)
treec6df3e3693951e2f39044077caec079fb0708509 /src/basic/escape.c
parentMerge pull request #15315 from DaanDeMeyer/deprecate-sd-bus-priority (diff)
downloadsystemd-2b99f645c672efa239a6b8ab1ee2c084474cebba.tar.xz
systemd-2b99f645c672efa239a6b8ab1ee2c084474cebba.zip
shared/escape: add new escape style with \n\t escaped
Diffstat (limited to 'src/basic/escape.c')
-rw-r--r--src/basic/escape.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/basic/escape.c b/src/basic/escape.c
index c5c44d2e7d..116efa4119 100644
--- a/src/basic/escape.c
+++ b/src/basic/escape.c
@@ -518,22 +518,28 @@ char* shell_maybe_quote(const char *s, EscapeStyle style) {
return NULL;
t = r;
- if (style == ESCAPE_BACKSLASH)
+ switch (style) {
+ case ESCAPE_BACKSLASH:
+ case ESCAPE_BACKSLASH_ONELINE:
*(t++) = '"';
- else if (style == ESCAPE_POSIX) {
+ break;
+ case ESCAPE_POSIX:
*(t++) = '$';
*(t++) = '\'';
- } else
+ break;
+ default:
assert_not_reached("Bad EscapeStyle");
+ }
t = mempcpy(t, s, p - s);
- if (style == ESCAPE_BACKSLASH)
- t = strcpy_backslash_escaped(t, p, SHELL_NEED_ESCAPE, false);
+ if (IN_SET(style, ESCAPE_BACKSLASH, ESCAPE_BACKSLASH_ONELINE))
+ t = strcpy_backslash_escaped(t, p, SHELL_NEED_ESCAPE,
+ style == ESCAPE_BACKSLASH_ONELINE);
else
t = strcpy_backslash_escaped(t, p, SHELL_NEED_ESCAPE_POSIX, true);
- if (style == ESCAPE_BACKSLASH)
+ if (IN_SET(style, ESCAPE_BACKSLASH, ESCAPE_BACKSLASH_ONELINE))
*(t++) = '"';
else
*(t++) = '\'';