You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Encountered a panic while encoding a complex /generated) struct using the xml encoder from xml package. I then narrowed it down to a simple case to reproduce the panic with. Have a look at this code: https://go.dev/play/p/laLC5qg3x3E
It first unmarshalls an example XML to ensure, the struct definition is working. Then it assembles a struct with example data and encodes it using a new XML encoder which then shows the panic in question.
If you then change the refrence "LayerTwo" to a value by removing the asterisk, the panic is gone. So it happens only if the embedded struct is a reference and it contains an optional attribute.
Looking at the code of the marshaller in xml/marshall.go, it seems around line 511 and following, testing on the processed value beeing an attribute and not nil and the parent element not beeing empty does not cover this case.
What did you expect to see?
I expect no panic to occur and proper XML to be rendered.
What did you see instead?
A panic as shown in the above example in playground.
The text was updated successfully, but these errors were encountered:
cherrymui
changed the title
xml: embedded reference to substruct causes XML marshaller to panic on encoding
encoding/xml: embedded reference to substruct causes XML marshaller to panic on encoding
Dec 14, 2021
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?linux/amd64
go env
OutputWhat did you do?
Encountered a panic while encoding a complex /generated) struct using the xml encoder from xml package. I then narrowed it down to a simple case to reproduce the panic with. Have a look at this code:
https://go.dev/play/p/laLC5qg3x3E
It first unmarshalls an example XML to ensure, the struct definition is working. Then it assembles a struct with example data and encodes it using a new XML encoder which then shows the panic in question.
If you then change the refrence "LayerTwo" to a value by removing the asterisk, the panic is gone. So it happens only if the embedded struct is a reference and it contains an optional attribute.
Looking at the code of the marshaller in xml/marshall.go, it seems around line 511 and following, testing on the processed value beeing an attribute and not nil and the parent element not beeing empty does not cover this case.
What did you expect to see?
I expect no panic to occur and proper XML to be rendered.
What did you see instead?
A panic as shown in the above example in playground.
The text was updated successfully, but these errors were encountered: