Skip to content

Commit

Permalink
Fix Params case handling in the new site global
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Jan 20, 2019
1 parent db3c49d commit fb17850
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions hugolib/case_insensitive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ Shortcode Site: {{ .Page.Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
writeToFs(t, fs, "layouts/partials/partial.html", `
Partial Page: {{ .Params.COLOR }}|{{ .Params.Colors.Blue }}
Partial Site: {{ .Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
Partial Site Global: {{ site.Params.COLOR }}|{{ site.Params.COLORS.YELLOW }}
`)

writeToFs(t, fs, "config.toml", caseMixingSiteConfigTOML)
Expand Down Expand Up @@ -200,6 +201,7 @@ Site Colors: {{ .Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
"Shortcode Site: green|yellow",
"Partial Page: red|heavenly",
"Partial Site: green|yellow",
"Partial Site Global: green|yellow",
"Page Title: Side 1",
"Site Title: Nynorsk title",
"«Hi»", // angled quotes
Expand Down
3 changes: 2 additions & 1 deletion tpl/tplimpl/template_ast_transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ func (c *templateContext) paramsKeysToLower(n parse.Node) {
c.updateIdentsIfNeeded(an.Ident)
case *parse.PipeNode:
c.paramsKeysToLower(an)
case *parse.ChainNode:
c.updateIdentsIfNeeded(an.Field)
}

}
}
}
Expand Down
18 changes: 18 additions & 0 deletions tpl/tplimpl/template_ast_transformers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand Down Expand Up @@ -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 }}
`
)

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit fb17850

Please sign in to comment.