diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2020-08-18 11:28:46 +0200 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2020-08-19 08:32:51 +0200 |
commit | b1ffa2324eaf3e3d847ce4e0f738d6bf9e46a54b (patch) | |
tree | 8ad2adc65d5ab854b10e29c67f1a14643cddbe05 /pkg/systemd/generate/common_test.go | |
parent | 9d096c1c4ea5308c94f779444b61015eeef2972a (diff) | |
download | podman-b1ffa2324eaf3e3d847ce4e0f738d6bf9e46a54b.tar.gz podman-b1ffa2324eaf3e3d847ce4e0f738d6bf9e46a54b.tar.bz2 podman-b1ffa2324eaf3e3d847ce4e0f738d6bf9e46a54b.zip |
generate systemd: quote arguments with whitespace
Make sure that arguments with whitespace are properly quoted so they are
interpreted as one (and not multiple ones) by systemd.
Now `-e tz="america/new york"` will be generated as `-e "tz=america/new york"`.
The quotes are moving but the argument is still correct.
Fixes: #7285
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'pkg/systemd/generate/common_test.go')
-rw-r--r-- | pkg/systemd/generate/common_test.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/systemd/generate/common_test.go b/pkg/systemd/generate/common_test.go index 389c30f59..d0ec5637c 100644 --- a/pkg/systemd/generate/common_test.go +++ b/pkg/systemd/generate/common_test.go @@ -28,3 +28,28 @@ func TestFilterPodFlags(t *testing.T) { } } } + +func TestQuoteArguments(t *testing.T) { + tests := []struct { + input []string + output []string + }{ + { + []string{"foo", "bar=\"arg\""}, + []string{"foo", "bar=\"arg\""}, + }, + { + []string{"foo", "bar=\"arg with space\""}, + []string{"foo", "\"bar=\\\"arg with space\\\"\""}, + }, + { + []string{"foo", "bar=\"arg with\ttab\""}, + []string{"foo", "\"bar=\\\"arg with\\ttab\\\"\""}, + }, + } + + for _, test := range tests { + quoted := quoteArguments(test.input) + assert.Equal(t, test.output, quoted) + } +} |