From: Russ Cox Date: Mon, 26 Apr 2010 17:01:13 +0000 (-0700) Subject: template: fix handling of pointer inside interface X-Git-Tag: weekly.2010-04-27~42 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=13bb28a40a4745fa9961a9ca69a342d99b61bd2c;p=gostls13.git template: fix handling of pointer inside interface R=r CC=golang-dev https://golang.org/cl/982043 --- diff --git a/src/pkg/template/template.go b/src/pkg/template/template.go index 2bf21610b9..d15db7f8b8 100644 --- a/src/pkg/template/template.go +++ b/src/pkg/template/template.go @@ -596,7 +596,7 @@ func (st *state) findVar(s string) reflect.Value { return nil } if intf, ok := data.(*reflect.InterfaceValue); ok { - data = intf.Elem() + data = reflect.Indirect(intf.Elem()) } switch typ := data.Type().(type) { diff --git a/src/pkg/template/template_test.go b/src/pkg/template/template_test.go index 39c43e3e2d..a6267bfccf 100644 --- a/src/pkg/template/template_test.go +++ b/src/pkg/template/template_test.go @@ -48,6 +48,7 @@ type S struct { stringmap map[string]string bytes []byte iface interface{} + ifaceptr interface{} } func (s *S) pointerMethod() string { return "ptrmethod!" } @@ -385,6 +386,11 @@ var tests = []*Test{ out: "[1 2 3]", }, + &Test{ + in: "{.section ifaceptr}{item} {value}{.end}", + + out: "Item Value", + }, } func TestAll(t *testing.T) { @@ -423,6 +429,7 @@ func testAll(t *testing.T, parseFunc func(*Test) (*Template, os.Error)) { s.stringmap["stringkey2"] = "stringresult" s.bytes = []byte("hello") s.iface = []int{1, 2, 3} + s.ifaceptr = &T{"Item", "Value"} var buf bytes.Buffer for _, test := range tests {