Fix panic when unmarshaling into a map twice (#854)

Fixes #851
This commit is contained in:
Thomas Pelletier
2023-02-28 17:34:24 +01:00
committed by GitHub
parent 8a416daa69
commit 643c251c4b
2 changed files with 16 additions and 7 deletions
+15
View File
@@ -2472,6 +2472,21 @@ func TestIssue850(t *testing.T) {
require.Error(t, err)
}
func TestIssue851(t *testing.T) {
type Target struct {
Params map[string]string `toml:"params"`
}
content := "params = {a=\"1\",b=\"2\"}"
var target Target
err := toml.Unmarshal([]byte(content), &target)
require.NoError(t, err)
require.Equal(t, map[string]string{"a": "1", "b": "2"}, target.Params)
err = toml.Unmarshal([]byte(content), &target)
require.NoError(t, err)
require.Equal(t, map[string]string{"a": "1", "b": "2"}, target.Params)
}
func TestUnmarshalDecodeErrors(t *testing.T) {
examples := []struct {
desc string