Merge pull request #12545 from vrothberg/fix-12477

generate systemd: support entrypoint JSON strings
This commit is contained in:
OpenShift Merge Robot 2021-12-09 08:41:29 +00:00 committed by GitHub
commit 4a52a457d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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