diff options
| author | Rob Pike <r@golang.org> | 2012-04-03 11:44:52 +1000 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2012-04-03 11:44:52 +1000 |
| commit | 065db4ea99f80cce6d9ed794467697955f0eaa2e (patch) | |
| tree | d22a9bc9efb8c48779e2ea98bae8eeda22f04efa /src/pkg/text/template/exec.go | |
| parent | d3c92b7c903064f31c6f0aec4c3be5cfd30b0e53 (diff) | |
| download | go-065db4ea99f80cce6d9ed794467697955f0eaa2e.tar.xz | |
text/template: pipelined arg was not typechecked
Without this fix, an erroneous template causes a panic; should be caught safely.
The bug did not affect correct templates.
Fixes #3267.
R=golang-dev, dsymonds, rsc
CC=golang-dev
https://golang.org/cl/5900065
Diffstat (limited to 'src/pkg/text/template/exec.go')
| -rw-r--r-- | src/pkg/text/template/exec.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/pkg/text/template/exec.go b/src/pkg/text/template/exec.go index 9a720cf43e..feb434a3be 100644 --- a/src/pkg/text/template/exec.go +++ b/src/pkg/text/template/exec.go @@ -491,7 +491,11 @@ func (s *state) evalCall(dot, fun reflect.Value, name string, args []parse.Node, } // Add final value if necessary. if final.IsValid() { - argv[i] = final + t := typ.In(typ.NumIn() - 1) + if typ.IsVariadic() { + t = t.Elem() + } + argv[i] = s.validateType(final, t) } result := fun.Call(argv) // If we have an error that is not nil, stop execution and return that error to the caller. @@ -507,6 +511,7 @@ func (s *state) validateType(value reflect.Value, typ reflect.Type) reflect.Valu switch typ.Kind() { case reflect.Interface, reflect.Ptr, reflect.Chan, reflect.Map, reflect.Slice, reflect.Func: // An untyped nil interface{}. Accept as a proper nil value. + // TODO: Can we delete the other types in this list? Should we? value = reflect.Zero(typ) default: s.errorf("invalid value; expected %s", typ) |
