diff --git a/pkg/apis/workflow/v1alpha1/item.go b/pkg/apis/workflow/v1alpha1/item.go index 288cc57e633b..2093db605542 100644 --- a/pkg/apis/workflow/v1alpha1/item.go +++ b/pkg/apis/workflow/v1alpha1/item.go @@ -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. @@ -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) { diff --git a/pkg/apis/workflow/v1alpha1/item_test.go b/pkg/apis/workflow/v1alpha1/item_test.go index 6d06a613137f..141f60871b91 100644 --- a/pkg/apis/workflow/v1alpha1/item_test.go +++ b/pkg/apis/workflow/v1alpha1/item_test.go @@ -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"}, }