Skip to content

Commit

Permalink
Use different parameter quoting (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
tothszabi authored Dec 1, 2023
1 parent 35a7427 commit 921272d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"io"
"os/exec"
"strconv"
"strings"

"github.com/bitrise-io/go-utils/v2/env"
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}

0 comments on commit 921272d

Please sign in to comment.