From 13c313494ac138dda3d6328602cbe9ea122c135c Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Tue, 24 Jun 2025 16:57:11 +0000 Subject: [PATCH 1/2] fix(agent/agentcontainers): remove shellquote in favor of %q Shellquote modified `{{.Name}}` to `\{\{.Name}}` breaking Fish, by switching to quoting each arg individually we should have a more portable (across shells) implementation. --- agent/agentcontainers/execer.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/agent/agentcontainers/execer.go b/agent/agentcontainers/execer.go index 8bdb7f24390f3..323401f34ca81 100644 --- a/agent/agentcontainers/execer.go +++ b/agent/agentcontainers/execer.go @@ -2,10 +2,10 @@ package agentcontainers import ( "context" + "fmt" "os/exec" "runtime" - - "github.com/kballard/go-shellquote" + "strings" "cdr.dev/slog" "github.com/coder/coder/v2/agent/agentexec" @@ -56,7 +56,10 @@ func (e *commandEnvExecer) prepare(ctx context.Context, inName string, inArgs .. caller = "/c" } name = shell - args = []string{caller, shellquote.Join(append([]string{inName}, inArgs...)...)} + for _, arg := range append([]string{inName}, inArgs...) { + args = append(args, fmt.Sprintf("%q", arg)) + } + args = []string{caller, strings.Join(args, " ")} return name, args, dir, env } From d09fc112f076960cbac0868d8d8c24fb918a688e Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Tue, 24 Jun 2025 17:04:57 +0000 Subject: [PATCH 2/2] update test --- agent/agentcontainers/api_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/agent/agentcontainers/api_test.go b/agent/agentcontainers/api_test.go index a5541399f6437..9f6f46ac5e3a4 100644 --- a/agent/agentcontainers/api_test.go +++ b/agent/agentcontainers/api_test.go @@ -2040,7 +2040,7 @@ func TestAPI(t *testing.T) { // Verify commands were executed through the custom shell and environment. require.NotEmpty(t, fakeExec.commands, "commands should be executed") - // Want: /bin/custom-shell -c "docker ps --all --quiet --no-trunc" + // Want: /bin/custom-shell -c '"docker" "ps" "--all" "--quiet" "--no-trunc"' require.Equal(t, testShell, fakeExec.commands[0][0], "custom shell should be used") if runtime.GOOS == "windows" { require.Equal(t, "/c", fakeExec.commands[0][1], "shell should be called with /c on Windows") @@ -2049,6 +2049,7 @@ func TestAPI(t *testing.T) { } require.Len(t, fakeExec.commands[0], 3, "command should have 3 arguments") require.GreaterOrEqual(t, strings.Count(fakeExec.commands[0][2], " "), 2, "command/script should have multiple arguments") + require.True(t, strings.HasPrefix(fakeExec.commands[0][2], `"docker" "ps"`), "command should start with \"docker\" \"ps\"") // Verify the environment was set on the command. lastCmd := fakeExec.getLastCommand() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy