diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-01-18 17:48:19 +0000 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-01-20 12:42:24 +0000 |
commit | e1a66c7343db9d232749255dd9e3a58d94b86997 (patch) | |
tree | d627599de196ed8e08622226e5634cd602b08914 /tpl | |
parent | db3c49d049193e0fc225fe4bdb95712c311d6615 (diff) |
Fix Params case handling in the new site global
Fixes #5615
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/tplimpl/template_ast_transformers.go | 6 | ||||
-rw-r--r-- | tpl/tplimpl/template_ast_transformers_test.go | 18 |
2 files changed, 23 insertions, 1 deletions
diff --git a/tpl/tplimpl/template_ast_transformers.go b/tpl/tplimpl/template_ast_transformers.go index 1e1589308..f32b189ff 100644 --- a/tpl/tplimpl/template_ast_transformers.go +++ b/tpl/tplimpl/template_ast_transformers.go @@ -130,8 +130,12 @@ func (c *templateContext) paramsKeysToLower(n parse.Node) { c.updateIdentsIfNeeded(an.Ident) case *parse.PipeNode: c.paramsKeysToLower(an) + case *parse.ChainNode: + // site.Params... + if len(an.Field) > 1 && an.Field[0] == paramsIdentifier { + c.updateIdentsIfNeeded(an.Field) + } } - } } } diff --git a/tpl/tplimpl/template_ast_transformers_test.go b/tpl/tplimpl/template_ast_transformers_test.go index 52d8c17b1..45cf4399a 100644 --- a/tpl/tplimpl/template_ast_transformers_test.go +++ b/tpl/tplimpl/template_ast_transformers_test.go @@ -34,6 +34,13 @@ var ( "ByWeight": fmt.Sprintf("%v:%v:%v", seq, key, args), }, nil }, + "site": func() interface{} { + return map[string]interface{}{ + "Params": map[string]interface{}{ + "lower": "global-site", + }, + } + }, } paramsData = map[string]interface{}{ @@ -154,6 +161,12 @@ PARAMS TIME: {{ $time.Format "2006-01-02" }} {{ $_x := $.Params.MyDate | ToTime }} PARAMS TIME2: {{ $_x.AddDate 0 1 0 }} + +PARAMS SITE GLOBAL1: {{ site.Params.LOwER }} +{{ $lower := site.Params.LOwER }} +{{ $site := site }} +PARAMS SITE GLOBAL2: {{ $lower }} +PARAMS SITE GLOBAL3: {{ $site.Params.LOWER }} ` ) @@ -225,6 +238,11 @@ func TestParamsKeysToLower(t *testing.T) { require.Contains(t, result, "PARAMS TIME: 1972-02-28") require.Contains(t, result, "PARAMS TIME2: 1972-02-28") + // Issue ##5615 + require.Contains(t, result, "PARAMS SITE GLOBAL1: global-site") + require.Contains(t, result, "PARAMS SITE GLOBAL2: global-site") + require.Contains(t, result, "PARAMS SITE GLOBAL3: global-site") + } func BenchmarkTemplateParamsKeysToLower(b *testing.B) { |