]> Cypherpunks repositories - gostls13.git/commit
encoding/xml: only initialize nil struct fields when decoding
authorDaniel Martí <mvdan@mvdan.cc>
Tue, 24 Sep 2019 17:14:10 +0000 (18:14 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Thu, 28 May 2020 22:48:53 +0000 (22:48 +0000)
commit8f4151ea67e1d498e0880f28d3fd803dc2c5448f
tree9f5395a39da32e095bc3a3d828bc434edb3966d3
parent107ebb178176f00c988a40943446af6f672b1e63
encoding/xml: only initialize nil struct fields when decoding

fieldInfo.value used to initialize nil anonymous struct fields if they
were encountered. This behavior is wanted when decoding, but not when
encoding. When encoding, the value should never be modified, and these
nil fields should be skipped entirely.

To fix the bug, add a bool argument to the function which tells the
code whether we are encoding or decoding.

Finally, add a couple of tests to cover the edge cases pointed out in
the original issue.

Fixes #27240.

Change-Id: Ic97ae4bfe5f2062c8518e03d1dec07c3875e18f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/196809
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
src/encoding/xml/marshal.go
src/encoding/xml/marshal_test.go
src/encoding/xml/read.go
src/encoding/xml/typeinfo.go