mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/xml: Reset the parent stack before printing a chardata or comment field in a struct
This CL resets the parent stack when printing a character or comment field struct. In the case of XML elements, the previous parents stack must be considered. However, charadata or comment fields can't be printed in other fields so it seems required to reset the parent stack each time a chardata or comment field is printed. Fixes #5072 Change-Id: I84f61c9bfce94133cd0c076c11211b9be5b4b1ac Reviewed-on: https://go-review.googlesource.com/9910 Reviewed-by: Nigel Tao <nigeltao@golang.org> Reviewed-by: roger peppe <rogpeppe@gmail.com>
This commit is contained in:
parent
227fb116be
commit
2db587c029
2 changed files with 24 additions and 0 deletions
|
|
@ -924,6 +924,9 @@ func (p *printer) marshalStruct(tinfo *typeInfo, val reflect.Value) error {
|
|||
|
||||
switch finfo.flags & fMode {
|
||||
case fCharData:
|
||||
if err := s.setParents(&noField, reflect.Value{}); err != nil {
|
||||
return err
|
||||
}
|
||||
if vf.CanInterface() && vf.Type().Implements(textMarshalerType) {
|
||||
data, err := vf.Interface().(encoding.TextMarshaler).MarshalText()
|
||||
if err != nil {
|
||||
|
|
@ -967,6 +970,9 @@ func (p *printer) marshalStruct(tinfo *typeInfo, val reflect.Value) error {
|
|||
continue
|
||||
|
||||
case fComment:
|
||||
if err := s.setParents(&noField, reflect.Value{}); err != nil {
|
||||
return err
|
||||
}
|
||||
k := vf.Kind()
|
||||
if !(k == reflect.String || k == reflect.Slice && vf.Type().Elem().Kind() == reflect.Uint8) {
|
||||
return fmt.Errorf("xml: bad type for comment field of %s", val.Type())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue