Commit 1cd78eed authored by Rob Pike's avatar Rob Pike

text/template: fix bug in pipelined variadics

Simple bug in argument processing: The final arg may
be the pipeline value, in which case it gets bound to the
fixed argument section. The code got that wrong. Easy
to fix.

Fixes #8950.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/161750043
parent 65dde1ed
...@@ -546,7 +546,7 @@ func (s *state) evalCall(dot, fun reflect.Value, node parse.Node, name string, a ...@@ -546,7 +546,7 @@ func (s *state) evalCall(dot, fun reflect.Value, node parse.Node, name string, a
argv := make([]reflect.Value, numIn) argv := make([]reflect.Value, numIn)
// Args must be evaluated. Fixed args first. // Args must be evaluated. Fixed args first.
i := 0 i := 0
for ; i < numFixed; i++ { for ; i < numFixed && i < len(args); i++ {
argv[i] = s.evalArg(dot, typ.In(i), args[i]) argv[i] = s.evalArg(dot, typ.In(i), args[i])
} }
// Now the ... args. // Now the ... args.
......
...@@ -893,6 +893,18 @@ func TestMessageForExecuteEmpty(t *testing.T) { ...@@ -893,6 +893,18 @@ func TestMessageForExecuteEmpty(t *testing.T) {
} }
} }
func TestFinalForPrintf(t *testing.T) {
tmpl, err := New("").Parse(`{{"x" | printf}}`)
if err != nil {
t.Fatal(err)
}
var b bytes.Buffer
err = tmpl.Execute(&b, 0)
if err != nil {
t.Fatal(err)
}
}
type cmpTest struct { type cmpTest struct {
expr string expr string
truth string truth string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment