tpl/tplimpl: Fix .Site.Params case regression

Fixes #5094
This commit is contained in:
Bjørn Erik Pedersen 2018-08-19 13:30:42 +02:00
parent 834617f9f8
commit fdff0d3af4
2 changed files with 17 additions and 11 deletions

View file

@ -213,16 +213,6 @@ func (d decl) indexOfReplacementStart(idents []string) int {
// .Data.Params.someKey
return -1
}
if !d.isKeyword(container) {
// where $pages ".Params.toc_hide" "!=" true
return -1
}
}
if i < len(resolvedIdents)-1 {
next := resolvedIdents[i+1]
if !d.isKeyword(next) {
return -1
}
}
paramFound = true
@ -298,6 +288,11 @@ func (d decl) resolveVariables(idents []string) ([]string, bool) {
return nil, false
}
if !d.isKeyword(replacement) {
// This can not be .Site.Params etc.
return nil, false
}
replacement = strings.TrimPrefix(replacement, ".")
if replacement == "" {

View file

@ -24,7 +24,8 @@ import (
var (
testFuncs = map[string]interface{}{
"Echo": func(v interface{}) interface{} { return v },
"First": func(v ...interface{}) interface{} { return v[0] },
"Echo": func(v interface{}) interface{} { return v },
"where": func(seq, key interface{}, args ...interface{}) (interface{}, error) {
return map[string]interface{}{
"ByWeight": fmt.Sprintf("%v:%v:%v", seq, key, args),
@ -55,6 +56,9 @@ var (
"Language": map[string]interface{}{
"Params": map[string]interface{}{
"lower": "P22L",
"nested": map[string]interface{}{
"lower": "P22L_nested",
},
},
},
"Data": map[string]interface{}{
@ -84,6 +88,7 @@ P2_2: {{ $.Site.Params.LOWER }}
P2_3: {{ $site.Params.LOWER }}
P2_4: {{ $siteParams.LOWER }}
P22: {{ .Site.Language.Params.LOWER }}
P22_nested: {{ .Site.Language.Params.NESTED.LOWER }}
P3: {{ .Site.Data.Params.NOLOW }}
P3_2: {{ $.Site.Data.Params.NOLOW }}
P3_3: {{ $site.Data.Params.NOLOW }}
@ -135,6 +140,8 @@ PARAMS STRING: {{ $pages.ByWeight }}
PARAMS STRING2: {{ with $pages }}{{ .ByWeight }}{{ end }}
{{ $pages3 := where ".Params.TOC_HIDE" "!=" .Params.LOWER }}
PARAMS STRING3: {{ $pages3.ByWeight }}
{{ $first := First .Pages .Site.Params.LOWER }}
PARAMS COMPOSITE: {{ $first.ByWeight }}
`
)
@ -168,6 +175,7 @@ func TestParamsKeysToLower(t *testing.T) {
require.Contains(t, result, "P2_3: P2L")
require.Contains(t, result, "P2_4: P2L")
require.Contains(t, result, "P22: P22L")
require.Contains(t, result, "P22_nested: P22L_nested")
require.Contains(t, result, "P3: P3H")
require.Contains(t, result, "P3_2: P3H")
require.Contains(t, result, "P3_3: P3H")
@ -195,6 +203,9 @@ func TestParamsKeysToLower(t *testing.T) {
require.Contains(t, result, "PARAMS STRING2: foo:.Params.toc_hide:[!= true]")
require.Contains(t, result, "PARAMS STRING3: .Params.TOC_HIDE:!=:[P1L]")
// Issue #5094
require.Contains(t, result, "PARAMS COMPOSITE: [1 3]")
// Issue #5068
require.Contains(t, result, "PCurrentSection: pcurrentsection")