Commits

Anonymous committed 8039bd0

text/template: fix bug in evaluating a chain starting with a function.

R=golang-dev, alberto.garcia.hierro
CC=golang-dev
https://codereview.appspot.com/7861046

  • Participants
  • Parent commits 6270bc6

Comments (0)

Files changed (2)

src/pkg/text/template/exec.go

 		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:

src/pkg/text/template/exec_test.go

 	{"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 {
 	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{
-		"add":      add,
-		"count":    count,
-		"dddArg":   dddArg,
-		"echo":     echo,
-		"makemap":  makemap,
-		"oneArg":   oneArg,
-		"typeOf":   typeOf,
-		"vfunc":    vfunc,
-		"zeroArgs": zeroArgs,
-		"stringer": stringer,
+		"add":        add,
+		"count":      count,
+		"dddArg":     dddArg,
+		"echo":       echo,
+		"makemap":    makemap,
+		"mapOfThree": mapOfThree,
+		"oneArg":     oneArg,
+		"stringer":   stringer,
+		"typeOf":     typeOf,
+		"vfunc":      vfunc,
+		"zeroArgs":   zeroArgs,
 	}
 	for _, test := range execTests {
 		var tmpl *Template