template/interpolate: filter is case insensitive

This commit is contained in:
Mitchell Hashimoto 2015-05-27 10:09:11 -07:00
parent 41a6fe9fda
commit 9d2e926808
2 changed files with 20 additions and 2 deletions

View File

@ -74,14 +74,14 @@ func (f *RenderFilter) include(k string) bool {
} }
f.once.Do(f.init) f.once.Do(f.init)
_, ok := f.includeSet[k] _, ok := f.includeSet[strings.ToLower(k)]
return ok return ok
} }
func (f *RenderFilter) init() { func (f *RenderFilter) init() {
f.includeSet = make(map[string]struct{}) f.includeSet = make(map[string]struct{})
for _, v := range f.Include { for _, v := range f.Include {
f.includeSet[v] = struct{}{} f.includeSet[strings.ToLower(v)] = struct{}{}
} }
} }

View File

@ -76,6 +76,24 @@ func TestRenderMap(t *testing.T) {
Include: []string{"bar"}, Include: []string{"bar"},
}, },
}, },
"filter case-insensitive": {
map[string]interface{}{
"bar": "{{upper `baz`}}",
"foo": map[string]string{
"{{upper `bar`}}": "{{upper `baz`}}",
},
},
map[string]interface{}{
"bar": "BAZ",
"foo": map[string]string{
"{{upper `bar`}}": "{{upper `baz`}}",
},
},
&RenderFilter{
Include: []string{"baR"},
},
},
} }
ctx := &Context{} ctx := &Context{}