Skip to content

Commit

Permalink
fix: handle logging empty args in strings (argoproj#19324)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Crenshaw <[email protected]>
  • Loading branch information
crenshaw-dev committed Aug 6, 2024
1 parent 21ed19b commit 82e5363
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions util/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func RunWithExecRunOpts(cmd *exec.Cmd, opts ExecRunOpts) (string, error) {
func GetCommandArgsToLog(cmd *exec.Cmd) string {
var argsToLog []string
for _, arg := range cmd.Args {
if arg == "" {
argsToLog = append(argsToLog, `""`)
continue
}

containsSpace := false
for _, r := range arg {
if unicode.IsSpace(r) {
Expand Down
5 changes: 5 additions & 0 deletions util/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func Test_getCommandArgsToLog(t *testing.T) {
args: []string{"sh", "-c", `echo "hello world"`},
expected: `sh -c "echo \"hello world\""`,
},
{
name: "empty string arg",
args: []string{"sh", "-c", ""},
expected: `sh -c ""`,
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 82e5363

Please sign in to comment.