Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate systemd: support entrypoint JSON strings #12545

Merged
merged 1 commit into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/systemd/generate/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion pkg/systemd/generate/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\""},
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion test/system/250-systemd.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down