Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
encoding/xml: handling of anonymous pointer fields is broken #27240
This happens on both Go 1.10.4 and
This playground link shows what
As one can see, they're simply skipped.
The XML package tries to print the zero values instead. Which seems fine in theory, but here's the first weird behavior - as you can see via the print statements, the encoded value has been modified in-place.
But here's an even worse problem - if the encoded value isn't addressable, encoding panics via reflect: https://play.golang.org/p/7ORK8Vw8o6Q
I think these two problems need to be fixed. I see two possibilities:
I personally strongly prefer option 1, as that would make
The only problem with option 1 is that this may break some existing programs, in which case option 2 may be better in Go 1.x. Although it would still be possible to achieve the existing behavior, if
Whatever we settle for, the fix should be pretty simple - happy to put in the work.
This is how I read the docs anyways and seems sane to me. It also makes the package more internally consistent: when the children of an anonymous field are promoted they're still behind a pointer so
I ended up dropping the ball on this a bit. The good news is that I had a mostly working fix last year, which I'm going to rebase, clean up a bit, and send.
I still think that option 1 is the correct solution here, which is the fix I implemented. I'm not sure if this bug is worth fixing, or if it's the correct fix, but it's not really doing anything sitting in a local branch for a year :)