Masterminds / sprig

Useful template functions for Go templates.
http://masterminds.github.io/sprig/
MIT License
4.07k stars 423 forks source link

Change return types of "split" and "splitn" to map[string]interface{} (instead of map[string]string) #397

Open rpasche opened 2 months ago

rpasche commented 2 months ago

Hi,

I just noticed, that I cannot use hasKey function on a dict created by the split or splitn functions, as they both return dicts of type map[string]string whereas most of the functions in dict.go expect a dict of type map[string]interface{}

{{- $mysplit := splitn "$" 2 "foo" }}
{{- if hasKey $mysplit "_1" }}
  2nd_part: {{ $mysplit._1 }}
{{- end }}

The error I get is

Error: template: .... at <$mysplit>: wrong type for value; expected map[string]interface {}; got map[string]string

Basically, the same error when trying to use get function

{{- $mysplit := splitn "$" 2 "foo" }}
1st_part: {{ get $mysplit. "_0" }}

The error I get is

Error: template: .... at <$mysplit>: wrong type for value; expected map[string]interface {}; got map[string]string