]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/xml: fix decoding of xml.Name with sub-elements
authorGustavo Niemeyer <gustavo@niemeyer.net>
Mon, 30 Jan 2012 18:32:48 +0000 (16:32 -0200)
committerGustavo Niemeyer <gustavo@niemeyer.net>
Mon, 30 Jan 2012 18:32:48 +0000 (16:32 -0200)
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5569090

src/pkg/encoding/xml/marshal_test.go
src/pkg/encoding/xml/read.go

index e0be33200864e9af9ffcc346963057f644fd0b6d..0f6c0f0795d7734467cfca0822612548181d180a 100644 (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.
        {
index 871fe059cfa1880d0cf1790368b77048deb1bbff..3193cda79258c27673b25a438e7ec96785ce4f1c 100644 (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