]> Cypherpunks repositories - gostls13.git/commitdiff
text/template: fix bug in pipelined variadics
authorRob Pike <r@golang.org>
Sat, 18 Oct 2014 18:22:05 +0000 (11:22 -0700)
committerRob Pike <r@golang.org>
Sat, 18 Oct 2014 18:22:05 +0000 (11:22 -0700)
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

src/text/template/exec.go
src/text/template/exec_test.go

index f6eed662b7c807b34fd10476a89fc8a0a70c6ad7..b00e10c7e418460b4b6ba082e6e53172abdd14c9 100644 (file)
@@ -546,7 +546,7 @@ func (s *state) evalCall(dot, fun reflect.Value, node parse.Node, name string, a
        argv := make([]reflect.Value, numIn)
        // Args must be evaluated. Fixed args first.
        i := 0
-       for ; i < numFixed; i++ {
+       for ; i < numFixed && i < len(args); i++ {
                argv[i] = s.evalArg(dot, typ.In(i), args[i])
        }
        // Now the ... args.
index e2cf2d370574c3829670ca0b4b371f8cfe4c9632..69c213ed24503b59487fed5efc03d00f484d063d 100644 (file)
@@ -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 {
        expr  string
        truth string