-
-
Notifications
You must be signed in to change notification settings - Fork 531
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
Return []any
for hash arrays when decoding to map / any.
#421
base: master
Are you sure you want to change the base?
Conversation
In principle this looks good at a glance. My main concern is that it might break compatibility where people use the type in some way; that's also why I haven't changed it before. I'm not entirely sure if that fear is warranted though. The fuzzer does seem to fail on the round-trip test though. |
Agree. It would be safest to put this in a new major version as a breaking change, if you guys are willing to do that. Even if I don't think many people will be affected by it, judging by the lack of related reported issues (that I could find at least). About the fuzzer, I'm a bit confused. Is it failing to parse / decode In my machine it seems to work fine: package main
import (
"fmt"
"encoding/json"
"github.com/BurntSushi/toml"
)
func main() {
t := `l=[{''.''=1},"",{''.''.''.''.''.''.''.''.''.''.''.''=0}]`
var data any
toml.Unmarshal([]byte(t), &data)
pp, _ := json.Marshal(data)
fmt.Println(string(pp))
} Outputs
I have a |
It's this bit that fails: https://github.com/BurntSushi/toml/blob/master/ossfuzz/fuzz.go#L36 It's the decode + encode + decode that errors, not just a decode. Here's a test case:
On your branch:
On master:
I haven't looked into it why this fails beyond reproducing it. Regardless of what we do with respect of compatibility, that should probably work. |
Thank you. One more TODO gone. Had to create an specific function for setting the types of hashes because |
Currently they are returned in
[]map[string]any
, which makes the tree impractical to traverse.Example: https://github.com/itchyny/gojq/blob/0607aa5af33a4f980e3e769a1820db80e3cc7b23/encoder.go#L72 triggers the panic, instead of being encoded as an array.
Before my changes, the library depended on the peculiar behaviour of hash arrays and unfinished inline arrays being
[]map[string]any
while finished inline arrays became[]any
. That was relevant for preventing finished inline arrays from being added to.Since now everything is
[]any
, I addedlocked
to the key info once the inline array (or any top-level field, really) is finished in order to be able to tell.I'm not happy about the duplicate error lines, but am not sure it would be better to engineer something just for that.