Skip to content

Commit

Permalink
Fix GetPage Params case issue
Browse files Browse the repository at this point in the history
Fixes #5946
  • Loading branch information
bep committed Nov 22, 2019
1 parent 628efd6 commit cd07e6d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
5 changes: 5 additions & 0 deletions hugolib/case_insensitive_test.go
Expand Up @@ -179,6 +179,10 @@ Site Title: {{ .Site.Title }}
Site Lang Mood: {{ .Site.Language.Params.MOoD }}
Page Colors: {{ .Params.COLOR }}|{{ .Params.Colors.Blue }}
Site Colors: {{ .Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
{{ $page2 := .Site.GetPage "/sect2/page2" }}
{{ if $page2 }}
Page2: {{ $page2.Params.ColoR }}
{{ end }}
{{ .Content }}
{{ partial "partial.html" . }}
`)
Expand Down Expand Up @@ -207,6 +211,7 @@ Site Colors: {{ .Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
"Page Title: Side 1",
"Site Title: Nynorsk title",
"«Hi»", // angled quotes
"Page2: black ",
)

th.assertFileContent(filepath.Join("public", "en", "sect1", "page1", "index.html"),
Expand Down
2 changes: 1 addition & 1 deletion hugolib/testhelpers_test.go
Expand Up @@ -743,7 +743,7 @@ func (th testHelper) assertFileContent(filename string, matches ...string) {
content := readDestination(th, th.Fs, filename)
for _, match := range matches {
match = th.replaceDefaultContentLanguageValue(match)
th.Assert(strings.Contains(content, match), qt.Equals, true)
th.Assert(strings.Contains(content, match), qt.Equals, true, qt.Commentf(content))
}
}

Expand Down
3 changes: 1 addition & 2 deletions tpl/tplimpl/template_ast_transformers.go
Expand Up @@ -508,8 +508,7 @@ func (d decl) resolveVariables(idents []string) ([]string, bool) {
}

if !d.isKeyword(replacement) {
// This can not be .Site.Params etc.
return nil, false
continue
}

replacement = strings.TrimPrefix(replacement, ".")
Expand Down
44 changes: 41 additions & 3 deletions tpl/tplimpl/template_ast_transformers_test.go
Expand Up @@ -26,6 +26,19 @@ import (
qt "github.com/frankban/quicktest"
)

type paramsHolder struct {
params map[string]interface{}
page *paramsHolder
}

func (p paramsHolder) Params() map[string]interface{} {
return p.params
}

func (p paramsHolder) GetPage(arg string) *paramsHolder {
return p.page
}

var (
testFuncs = map[string]interface{}{
"getif": func(v interface{}) interface{} { return v },
Expand All @@ -37,16 +50,22 @@ var (
"ByWeight": fmt.Sprintf("%v:%v:%v", seq, key, args),
}, nil
},
"site": func() interface{} {
return map[string]interface{}{
"Params": map[string]interface{}{
"site": func() paramsHolder {
return paramsHolder{
params: map[string]interface{}{
"lower": "global-site",
},
page: &paramsHolder{
params: map[string]interface{}{
"lower": "page",
},
},
}
},
}

paramsData = map[string]interface{}{

"NotParam": "Hi There",
"Slice": []int{1, 3},
"Params": map[string]interface{}{
Expand Down Expand Up @@ -81,6 +100,16 @@ var (
},
},
},
"Site2": paramsHolder{
params: map[string]interface{}{
"lower": "global-site",
},
page: &paramsHolder{
params: map[string]interface{}{
"lower": "page",
},
},
},
}

paramsTempl = `
Expand Down Expand Up @@ -170,6 +199,11 @@ PARAMS SITE GLOBAL1: {{ site.Params.LOwER }}
{{ $site := site }}
PARAMS SITE GLOBAL2: {{ $lower }}
PARAMS SITE GLOBAL3: {{ $site.Params.LOWER }}
{{ $p := $site.GetPage "foo" }}
PARAMS GETPAGE: {{ $p.Params.LOWER }}
{{ $p := .Site2.GetPage "foo" }}
PARAMS GETPAGE2: {{ $p.Params.LOWER }}
`
)

Expand Down Expand Up @@ -248,6 +282,10 @@ func TestParamsKeysToLower(t *testing.T) {
c.Assert(result, qt.Contains, "PARAMS SITE GLOBAL2: global-site")
c.Assert(result, qt.Contains, "PARAMS SITE GLOBAL3: global-site")

//
c.Assert(result, qt.Contains, "PARAMS GETPAGE: page")
c.Assert(result, qt.Contains, "PARAMS GETPAGE2: page")

}

func BenchmarkTemplateParamsKeysToLower(b *testing.B) {
Expand Down

0 comments on commit cd07e6d

Please sign in to comment.