diff options
author | Rob Pike <r@golang.org> | 2014-10-18 11:22:05 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2014-10-18 11:22:05 -0700 |
commit | a6baa662d04a1cebf2507dea9d030836da673c84 (patch) | |
tree | 875a47e69b4f6947da0c5026f66baea67b6560be /src/text | |
parent | 30af0431f29fe27d61bfdf45b9ad410ceb8c6074 (diff) | |
download | go-a6baa662d04a1cebf2507dea9d030836da673c84.tar.gz |
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 issue 8950.
LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://codereview.appspot.com/161750043
Diffstat (limited to 'src/text')
-rw-r--r-- | src/text/template/exec.go | 2 | ||||
-rw-r--r-- | src/text/template/exec_test.go | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/text/template/exec.go b/src/text/template/exec.go index f6eed662b..b00e10c7e 100644 --- a/src/text/template/exec.go +++ b/src/text/template/exec.go @@ -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. diff --git a/src/text/template/exec_test.go b/src/text/template/exec_test.go index e2cf2d370..69c213ed2 100644 --- a/src/text/template/exec_test.go +++ b/src/text/template/exec_test.go @@ -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 |