From 9c497443ae0aca6ae5b66dfa6d3127c8605bd3a8 Mon Sep 17 00:00:00 2001 From: Gustavo Niemeyer Date: Mon, 30 Jan 2012 16:32:48 -0200 Subject: [PATCH] encoding/xml: fix decoding of xml.Name with sub-elements R=golang-dev, adg CC=golang-dev https://golang.org/cl/5569090 --- src/pkg/encoding/xml/marshal_test.go | 5 +++++ src/pkg/encoding/xml/read.go | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pkg/encoding/xml/marshal_test.go b/src/pkg/encoding/xml/marshal_test.go index e0be3320086..0f6c0f0795d 100644 --- a/src/pkg/encoding/xml/marshal_test.go +++ b/src/pkg/encoding/xml/marshal_test.go @@ -532,6 +532,11 @@ var marshalTests = []struct { Value: &NameInField{Name{Space: "ns", Local: "foo"}}, ExpectXML: ``, }, + { + Value: &NameInField{Name{Space: "ns", Local: "foo"}}, + ExpectXML: ``, + UnmarshalOnly: true, + }, // Marshaling zero xml.Name uses the tag or field name. { diff --git a/src/pkg/encoding/xml/read.go b/src/pkg/encoding/xml/read.go index 871fe059cfa..3193cda7925 100644 --- a/src/pkg/encoding/xml/read.go +++ b/src/pkg/encoding/xml/read.go @@ -265,12 +265,13 @@ func (p *Decoder) unmarshal(val reflect.Value, start *StartElement) error { saveData = v case reflect.Struct: - sv = v - typ := sv.Type() + typ := v.Type() if typ == nameType { v.Set(reflect.ValueOf(start.Name)) break } + + sv = v tinfo, err = getTypeInfo(typ) if err != nil { return err