Closed hilljgo closed 6 years ago
Awesome, thanks! I wonder what the correct behavior is here. It's clearly not panicking. However, it can't produce a useful, safe, two-way serializable answer in every case.
(Also: no property list emitter should have generated one with duplicate keys. Is it handcrafted?)
Hi @DHowett. I worked with @hilljgo when we uncovered this, and yep, it was exposed by a hand-crafted plist, which is a common use-case for us.
As I see it, there are two ways to go:
PayloadIdentifier
would be bar
.Decode()
already seems to have this intention, but this type assertion inside a recover
is failing because panic
was called somewhere with a string
instead of an error
.Both seem like fine approaches to me, with number 2 likely being a quicker fix and more explicit behavior. Do you have a preference?
map[string]interface{}
, not an interface{}
(!), andencoding/json
does the same thing, and 2 ended up being somewhat more burdensome.Ah, approach 3 (act like Apple) is the one that proved more burdensome. I didn't investigate 2, but I did determine that package reflect
is incorrectly panicking with a string.
(If I switch to package cf
(separate branch on this repo), which uses true maps to back cf.Dictionary
, the balance will shift to taking Apple's approach and not letting the duplicate value escape the parser.)
When attempting to unmarshal a plist that contains duplicate keys, a panic is hit.
Example code:
The following panic stack trace is returned: