Skip to content

Commit

Permalink
Use different parameter quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
tothszabi committed Dec 1, 2023
1 parent 119c237 commit 2508283
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package command

import (
"errors"
"fmt"
"io"
"os"
"os/exec"
"strconv"
"strings"
)

Expand Down Expand Up @@ -125,7 +125,7 @@ func (m Model) PrintableCommandArgs() string {
func PrintableCommandArgs(isQuoteFirst bool, fullCommandArgs []string) string {
cmdArgsDecorated := []string{}
for idx, anArg := range fullCommandArgs {
quotedArg := strconv.Quote(anArg)
quotedArg := fmt.Sprintf("\"%s\"", anArg)
if idx == 0 && !isQuoteFirst {
quotedArg = anArg
}
Expand Down
15 changes: 15 additions & 0 deletions command/command_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package command_test

import (
"fmt"
"os/exec"
"testing"

"github.com/bitrise-io/go-utils/command"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -106,3 +108,16 @@ func TestRunCmdAndReturnExitCode(t *testing.T) {
})
}
}

func TestSpecialCharactersAreNotEscaped(t *testing.T) {
programName := "test"
argument := `-----BEGIN PRIVATE KEY-----\nThis\nis\na\nprivate-key\n-----END PRIVATE KEY-----`

cmd, err := command.NewWithParams(programName, argument)
require.NoError(t, err)

got := cmd.PrintableCommandArgs()
expected := fmt.Sprintf("%s \"%s\"", programName, argument)

assert.Equal(t, expected, got)
}

0 comments on commit 2508283

Please sign in to comment.