diff --git a/src/pkg/encoding/xml/marshal_test.go b/src/pkg/encoding/xml/marshal_test.go index 6beff17019..10871fd129 100644 --- a/src/pkg/encoding/xml/marshal_test.go +++ b/src/pkg/encoding/xml/marshal_test.go @@ -188,6 +188,10 @@ type PresenceTest struct { Exists *struct{} } +type IgnoreTest struct { + PublicSecret string `xml:"-"` +} + type MyBytes []byte type Data struct { @@ -592,6 +596,22 @@ var marshalTests = []struct { }, ExpectXML: `a1a2b1`, }, + + // Test ignoring fields via "-" tag + { + ExpectXML: ``, + Value: &IgnoreTest{}, + }, + { + ExpectXML: ``, + Value: &IgnoreTest{PublicSecret: "can't tell"}, + MarshalOnly: true, + }, + { + ExpectXML: `ignore me`, + Value: &IgnoreTest{}, + UnmarshalOnly: true, + }, } func TestMarshal(t *testing.T) { diff --git a/src/pkg/encoding/xml/typeinfo.go b/src/pkg/encoding/xml/typeinfo.go index 36b35ed2ee..2bf2c6b303 100644 --- a/src/pkg/encoding/xml/typeinfo.go +++ b/src/pkg/encoding/xml/typeinfo.go @@ -37,7 +37,6 @@ const ( fAny // TODO: - //fIgnore //fOmitEmpty fMode = fElement | fAttr | fCharData | fInnerXml | fComment | fAny @@ -62,7 +61,7 @@ func getTypeInfo(typ reflect.Type) (*typeInfo, error) { n := typ.NumField() for i := 0; i < n; i++ { f := typ.Field(i) - if f.PkgPath != "" { + if f.PkgPath != "" || f.Tag.Get("xml") == "-" { continue // Private field }