Decode: error on array table mismatched type (#804)
Prevent the decoder from continuing if it encounters a type it cannot decode an array table into. Fixes #799
This commit is contained in:
@@ -1735,6 +1735,28 @@ B = "data"`,
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "kv that points to a slice",
|
||||
input: "a.b.c = 'foo'",
|
||||
gen: func() test {
|
||||
doc := map[string][]string{}
|
||||
return test{
|
||||
target: &doc,
|
||||
err: true,
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "kv that points to a pointer to a slice",
|
||||
input: "a.b.c = 'foo'",
|
||||
gen: func() test {
|
||||
doc := map[string]*[]string{}
|
||||
return test{
|
||||
target: &doc,
|
||||
err: true,
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, e := range examples {
|
||||
@@ -2413,6 +2435,22 @@ Host = 'main.domain.com'
|
||||
require.Equal(t, expected, string(b))
|
||||
}
|
||||
|
||||
func TestIssue799(t *testing.T) {
|
||||
const testTOML = `
|
||||
# notice the double brackets
|
||||
[[test]]
|
||||
answer = 42
|
||||
`
|
||||
|
||||
var s struct {
|
||||
// should be []map[string]int
|
||||
Test map[string]int `toml:"test"`
|
||||
}
|
||||
|
||||
err := toml.Unmarshal([]byte(testTOML), &s)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestUnmarshalDecodeErrors(t *testing.T) {
|
||||
examples := []struct {
|
||||
desc string
|
||||
|
||||
Reference in New Issue
Block a user