Skip to content

Commit

Permalink
Merge branch 'master' into NOJIRA-original-command-error
Browse files Browse the repository at this point in the history
  • Loading branch information
lpusok authored Jan 30, 2024
2 parents 524118c + 921272d commit c816a64
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 @@ -157,7 +156,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 c816a64

Please sign in to comment.