mirror of
https://github.com/golang/go
synced 2024-11-20 01:14:40 -07:00
text/template: fix bug in evaluating a chain starting with a function.
R=golang-dev, alberto.garcia.hierro CC=golang-dev https://golang.org/cl/7861046
This commit is contained in:
parent
b06b77b8cf
commit
99645db926
@ -619,6 +619,8 @@ func (s *state) evalArg(dot reflect.Value, typ reflect.Type, n parse.Node) refle
|
||||
return s.validateType(s.evalVariableNode(dot, arg, nil, zero), typ)
|
||||
case *parse.PipeNode:
|
||||
return s.validateType(s.evalPipeline(dot, arg), typ)
|
||||
case *parse.IdentifierNode:
|
||||
return s.evalFunction(dot, arg, arg, nil, zero)
|
||||
}
|
||||
switch typ.Kind() {
|
||||
case reflect.Bool:
|
||||
|
@ -499,6 +499,8 @@ var execTests = []execTest{
|
||||
{"bug8b", "{{4|dddArg 3}}", "", tVal, false},
|
||||
// A bug was introduced that broke map lookups for lower-case names.
|
||||
{"bug9", "{{.cause}}", "neglect", map[string]string{"cause": "neglect"}, true},
|
||||
// Field chain starting with function did not work.
|
||||
{"bug10", "{{mapOfThree.three}}-{{(mapOfThree).three}}", "3-3", 0, true},
|
||||
}
|
||||
|
||||
func zeroArgs() string {
|
||||
@ -560,6 +562,10 @@ func stringer(s fmt.Stringer) string {
|
||||
return s.String()
|
||||
}
|
||||
|
||||
func mapOfThree() interface{} {
|
||||
return map[string]int{"three": 3}
|
||||
}
|
||||
|
||||
func testExecute(execTests []execTest, template *Template, t *testing.T) {
|
||||
b := new(bytes.Buffer)
|
||||
funcs := FuncMap{
|
||||
@ -568,11 +574,12 @@ func testExecute(execTests []execTest, template *Template, t *testing.T) {
|
||||
"dddArg": dddArg,
|
||||
"echo": echo,
|
||||
"makemap": makemap,
|
||||
"mapOfThree": mapOfThree,
|
||||
"oneArg": oneArg,
|
||||
"stringer": stringer,
|
||||
"typeOf": typeOf,
|
||||
"vfunc": vfunc,
|
||||
"zeroArgs": zeroArgs,
|
||||
"stringer": stringer,
|
||||
}
|
||||
for _, test := range execTests {
|
||||
var tmpl *Template
|
||||
|
Loading…
Reference in New Issue
Block a user