1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:44:39 -07:00

encoding/xml: fix decoding of xml.Name with sub-elements

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5569090
This commit is contained in:
Gustavo Niemeyer 2012-01-30 16:32:48 -02:00
parent ff8133d42e
commit 9c497443ae
2 changed files with 8 additions and 2 deletions

View File

@ -532,6 +532,11 @@ var marshalTests = []struct {
Value: &NameInField{Name{Space: "ns", Local: "foo"}},
ExpectXML: `<NameInField><foo xmlns="ns"></foo></NameInField>`,
},
{
Value: &NameInField{Name{Space: "ns", Local: "foo"}},
ExpectXML: `<NameInField><foo xmlns="ns"><ignore></ignore></foo></NameInField>`,
UnmarshalOnly: true,
},
// Marshaling zero xml.Name uses the tag or field name.
{

View File

@ -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