Skip to content

Commit

Permalink
add TestUnmarshalArrayOfTables and placeholder error; towards pelleti…
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Feb 4, 2023
1 parent 090cccf commit cedfd51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion unmarshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,11 @@ func (d *decoder) handleArrayTableCollection(key unstable.Iterator, v reflect.Va

return v, nil
case reflect.Slice:
elem := v.Index(v.Len() - 1)
idx := v.Len() - 1
if idx < 0 {
return v, fmt.Errorf("TODO uninitialized array table")
}
elem := v.Index(idx)
x, err := d.handleArrayTable(key, elem)
if err != nil || d.skipUntilTable {
return reflect.Value{}, err
Expand Down
14 changes: 13 additions & 1 deletion unmarshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
"testing"
"time"

"github.com/pelletier/go-toml/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/pelletier/go-toml/v2"
)

func ExampleDecoder_DisallowUnknownFields() {
Expand Down Expand Up @@ -3301,3 +3302,14 @@ func TestUnmarshalEmbedNonString(t *testing.T) {
require.NoError(t, err)
require.Nil(t, d.Foo)
}

func TestUnmarshalArrayOfTables(t *testing.T) {
m := struct {
A []struct {
B struct{}
}
}{}
require.NotPanics(t, func() {
require.Error(t, toml.Unmarshal([]byte(`[[A.B]]`), &m))
})
}

0 comments on commit cedfd51

Please sign in to comment.