Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/xml: Unmarshal panics when using wrong type with ',innerxml' tag #15600

Closed
dominikh opened this issue May 8, 2016 · 4 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dominikh
Copy link
Member

dominikh commented May 8, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go version go1.6.2 linux/amd64
  2. What did you do?
    https://play.golang.org/p/EJ3Bch1Di6
  3. What did you expect to see?
    An error that the type of the field is wrong
  4. What did you see instead?
panic: reflect.Set: value of type []uint8 is not assignable to type []int

goroutine 1 [running]:
panic(0x4f1740, 0xc82000a430)
    /usr/lib/go/src/runtime/panic.go:481 +0x3e6
reflect.Value.assignTo(0x4ea680, 0xc820010320, 0x97, 0x549580, 0xb, 0x4e9120, 0x0, 0x0, 0x0, 0x0)
    /usr/lib/go/src/reflect/value.go:2164 +0x3be
reflect.Value.Set(0x4e9120, 0xc820010240, 0x197, 0x4ea680, 0xc820010320, 0x97)
    /usr/lib/go/src/reflect/value.go:1334 +0x95
encoding/xml.(*Decoder).unmarshal(0xc8200b6000, 0x51a180, 0xc820010240, 0x199, 0xc820014240, 0x0, 0x0)
    /usr/lib/go/src/encoding/xml/read.go:549 +0x1c1b
encoding/xml.(*Decoder).DecodeElement(0xc8200b6000, 0x4e4320, 0xc820010240, 0x0, 0x0, 0x0)
    /usr/lib/go/src/encoding/xml/read.go:133 +0x1c3
encoding/xml.(*Decoder).Decode(0xc8200b6000, 0x4e4320, 0xc820010240, 0x0, 0x0)
    /usr/lib/go/src/encoding/xml/read.go:121 +0x4a
encoding/xml.Unmarshal(0xc820010260, 0x11, 0x20, 0x4e4320, 0xc820010240, 0x0, 0x0)
    /usr/lib/go/src/encoding/xml/read.go:115 +0x270
main.main()
    /tmp/foo.go:15 +0xcf
@bradfitz bradfitz added this to the Go1.8Maybe milestone May 10, 2016
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 10, 2016
@rsc
Copy link
Contributor

rsc commented Nov 2, 2016

Good next issue for @quentinmit.

@quentinmit
Copy link
Contributor

The docs say:

If the struct has a field of type []byte or string with tag
",innerxml", Unmarshal accumulates the raw XML nested inside the
element in that field. The rest of the rules still apply.

Given that documentation, I don't believe this should be an error - I think it should be treated as if innerxml had not been specified at all.

@rsc, what do you think?

@quentinmit
Copy link
Contributor

Also, that is already the behavior we have if innerxml is specified on a field that is not a string or a slice.

@gopherbot
Copy link

CL https://golang.org/cl/32919 mentions this issue.

@golang golang locked and limited conversation to collaborators Nov 9, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants