Decoder: prevent modification of inline tables (#702)

Fixes #701
This commit is contained in:
Thomas Pelletier
2021-12-12 09:43:42 -05:00
committed by GitHub
parent 8bbb519477
commit facb2b13e8
2 changed files with 47 additions and 1 deletions
+28 -1
View File
@@ -2270,7 +2270,34 @@ Program = "hugo"
require.Equal(t, expected, p)
}
//nolint:funlen
func TestIssue701(t *testing.T) {
// Expected behavior:
// Return an error since a cannot be modified. From the TOML spec:
//
// > Inline tables are fully self-contained and define all
// keys and sub-tables within them. Keys and sub-tables cannot
// be added outside the braces.
docs := []string{
`
a={}
[a.b]
z=0
`,
`
a={}
[[a.b]]
z=0
`,
}
for _, doc := range docs {
var v interface{}
err := toml.Unmarshal([]byte(doc), &v)
assert.Error(t, err)
}
}
func TestUnmarshalDecodeErrors(t *testing.T) {
examples := []struct {
desc string