diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-12-09 08:41:29 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-09 08:41:29 +0000 |
commit | 4a52a457d1e33a4817e4ce1dca390ba942eaec44 (patch) | |
tree | 61ac59417c30731a53a2a5e8e644aba3149eb432 | |
parent | 02eaebda46418d6a69a54a08066080fa24f38ebe (diff) | |
parent | 2d517b687b0832a6240a165e8aacef2876b9228a (diff) | |
download | podman-4a52a457d1e33a4817e4ce1dca390ba942eaec44.tar.gz podman-4a52a457d1e33a4817e4ce1dca390ba942eaec44.tar.bz2 podman-4a52a457d1e33a4817e4ce1dca390ba942eaec44.zip |
Merge pull request #12545 from vrothberg/fix-12477
generate systemd: support entrypoint JSON strings
-rw-r--r-- | pkg/systemd/generate/common.go | 2 | ||||
-rw-r--r-- | pkg/systemd/generate/common_test.go | 18 | ||||
-rw-r--r-- | test/system/250-systemd.bats | 3 |
3 files changed, 20 insertions, 3 deletions
diff --git a/pkg/systemd/generate/common.go b/pkg/systemd/generate/common.go index 24c85a27e..8689e084c 100644 --- a/pkg/systemd/generate/common.go +++ b/pkg/systemd/generate/common.go @@ -101,7 +101,7 @@ func escapeSystemdArguments(command []string) []string { func escapeSystemdArg(arg string) string { arg = strings.ReplaceAll(arg, "$", "$$") arg = strings.ReplaceAll(arg, "%", "%%") - if strings.ContainsAny(arg, " \t") { + if strings.ContainsAny(arg, " \t\"") { arg = strconv.Quote(arg) } else if strings.Contains(arg, `\`) { // strconv.Quote also escapes backslashes so diff --git a/pkg/systemd/generate/common_test.go b/pkg/systemd/generate/common_test.go index 45004ecb0..b9a43df8c 100644 --- a/pkg/systemd/generate/common_test.go +++ b/pkg/systemd/generate/common_test.go @@ -146,7 +146,7 @@ func TestEscapeSystemdArguments(t *testing.T) { }{ { []string{"foo", "bar=\"arg\""}, - []string{"foo", "bar=\"arg\""}, + []string{"foo", "\"bar=\\\"arg\\\"\""}, }, { []string{"foo", "bar=\"arg with space\""}, @@ -192,6 +192,22 @@ func TestEscapeSystemdArguments(t *testing.T) { []string{"foo", `command with two backslashes \\`}, []string{"foo", `"command with two backslashes \\\\"`}, }, + { + []string{"podman", "create", "--entrypoint", "foo"}, + []string{"podman", "create", "--entrypoint", "foo"}, + }, + { + []string{"podman", "create", "--entrypoint=foo"}, + []string{"podman", "create", "--entrypoint=foo"}, + }, + { + []string{"podman", "create", "--entrypoint", "[\"foo\"]"}, + []string{"podman", "create", "--entrypoint", "\"[\\\"foo\\\"]\""}, + }, + { + []string{"podman", "create", "--entrypoint", "[\"sh\", \"-c\", \"date '+%s'\"]"}, + []string{"podman", "create", "--entrypoint", "\"[\\\"sh\\\", \\\"-c\\\", \\\"date '+%%s'\\\"]\""}, + }, } for _, test := range tests { diff --git a/test/system/250-systemd.bats b/test/system/250-systemd.bats index 56d36934d..c49727cc9 100644 --- a/test/system/250-systemd.bats +++ b/test/system/250-systemd.bats @@ -104,8 +104,9 @@ function service_cleanup() { } @test "podman autoupdate local" { + # Note that the entrypoint may be a JSON string which requires preserving the quotes (see #12477) cname=$(random_string) - run_podman create --name $cname --label "io.containers.autoupdate=local" $IMAGE top + run_podman create --name $cname --label "io.containers.autoupdate=local" --entrypoint '["top"]' $IMAGE # Start systemd service to run this container service_setup |