Skip to content

Commit

Permalink
fix(controller): Work-around Golang bug. Fixes #5192 (#5230)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Collins <alex_collins@intuit.com>
  • Loading branch information
alexec committed Mar 2, 2021
1 parent 1454209 commit c4bcabd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/apis/workflow/v1alpha1/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"fmt"
"strconv"

jsonutil "github.com/argoproj/argo-workflows/v3/util/json"
)

// Type represents the stored type of Item.
Expand Down Expand Up @@ -58,15 +60,15 @@ func (i *Item) UnmarshalJSON(value []byte) error {
}

func (i *Item) String() string {
jsonBytes, err := json.Marshal(i)
x, err := json.Marshal(i) // this produces a normalised string, e.g. white-space
if err != nil {
panic(err)
}
// this convenience to remove quotes from strings will cause many problems
if jsonBytes[0] == '"' {
return string(jsonBytes[1 : len(jsonBytes)-1])
if x[0] == '"' {
return jsonutil.Fix(string(x[1 : len(x)-1]))
}
return string(jsonBytes)
return jsonutil.Fix(string(x))
}

func (i Item) Format(s fmt.State, _ rune) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/workflow/v1alpha1/item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ var testItemStringTable = []struct {
str string
}{
{"json-string", []string{`{"foo": "bar"}`}, `["{\"foo\": \"bar\"}"]`},
{"flaw-string", "<&>", `<&>`},
{"array", []int{1, 2, 3}, "[1,2,3]"},
{"flaw-array", []string{"<&>"}, `["<&>"]`},
{"flaw-map", map[string]string{"foo": "<&>"}, `{"foo":"<&>"}`},
{"number", 1.1, "1.1"},
}

Expand Down

0 comments on commit c4bcabd

Please sign in to comment.