pull/31915/merge
Gagan Gupta 6 days ago committed by GitHub
commit aad5fbef2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -150,6 +150,7 @@ func fromYAMLArray(str string) []any {
// toTOML takes an interface, marshals it to toml, and returns a string. It will
// always return a string, even on marshal error (empty string).
// Errors are swallowed, consistent with toYAML and toJSON behavior.
//
// This is designed to be called from a template.
func toTOML(v any) string {
@ -157,7 +158,8 @@ func toTOML(v any) string {
e := toml.NewEncoder(b)
err := e.Encode(v)
if err != nil {
return err.Error()
// Swallow errors inside of a template.
return ""
}
return b.String()
}

@ -122,6 +122,12 @@ keyInElement1 = "valueInElement1"`,
tpl: `{{ fromYamlArray . }}`,
expect: `[error unmarshaling JSON: while decoding JSON: json: cannot unmarshal object into Go value of type []interface {}]`,
vars: `hello: world`,
}, {
// toToml should swallow errors and return "" like toYaml and toJson do.
// map[int]string cannot be encoded as TOML (keys must be strings).
tpl: `{{ toToml . }}`,
expect: ``,
vars: map[int]string{1: "one"},
}, {
// This should never result in a network lookup. Regression for #7955
tpl: `{{ lookup "v1" "Namespace" "" "unlikelynamespace99999999" }}`,

Loading…
Cancel
Save