From 921272de13f5811b3a22dcd883459ea472c7f461 Mon Sep 17 00:00:00 2001 From: Szabolcs Toth <54896607+tothszabi@users.noreply.github.com> Date: Fri, 1 Dec 2023 09:54:08 +0000 Subject: [PATCH] Use different parameter quoting (#189) --- command/command.go | 3 +-- command/command_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/command/command.go b/command/command.go index 4206c2b..5672ef6 100644 --- a/command/command.go +++ b/command/command.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "os/exec" - "strconv" "strings" "github.com/bitrise-io/go-utils/v2/env" @@ -156,7 +155,7 @@ func (c command) Wait() error { func printableCommandArgs(isQuoteFirst bool, fullCommandArgs []string) string { var cmdArgsDecorated []string for idx, anArg := range fullCommandArgs { - quotedArg := strconv.Quote(anArg) + quotedArg := fmt.Sprintf("\"%s\"", anArg) if idx == 0 && !isQuoteFirst { quotedArg = anArg } diff --git a/command/command_test.go b/command/command_test.go index 1d6b8f6..e53b032 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -2,11 +2,13 @@ package command import ( "bytes" + "fmt" "os/exec" "strings" "testing" "github.com/bitrise-io/go-utils/v2/env" + "github.com/stretchr/testify/assert" ) func TestRunErrors(t *testing.T) { @@ -237,3 +239,13 @@ Error: fourth error`, }) } } + +func TestSpecialCharactersAreNotEscaped(t *testing.T) { + programName := "test" + argument := `-----BEGIN PRIVATE KEY-----\nThis\nis\na\nprivate-key\n-----END PRIVATE KEY-----` + + got := NewFactory(env.NewRepository()).Create(programName, []string{argument}, nil).PrintableCommandArgs() + expected := fmt.Sprintf("%s \"%s\"", programName, argument) + + assert.Equal(t, expected, got) +}