diff --git a/.golangci.yml b/.golangci.yml index bbf58aa..01859fe 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -64,6 +64,8 @@ issues: exclude: - 'ST1000: at least one file in a package should have a package comment' - 'package-comments: should have a package comment' + - 'G602: slice index out of range' + - 'G602: slice bounds out of range' exclude-rules: - path: (.+)_test.go linters: diff --git a/parser/element_fill.go b/parser/element_fill.go index a9fde49..5fc120a 100644 --- a/parser/element_fill.go +++ b/parser/element_fill.go @@ -458,6 +458,16 @@ func (f filler) fillRawMapWithTypedSlice(elt interface{}) (reflect.Value, error) eltValue.SetMapIndex(reflect.ValueOf(k), value) } + + case reflect.Slice: + for i, v := range elt.([]interface{}) { + value, err := f.fillRawMapWithTypedSlice(v) + if err != nil { + return eltValue, err + } + + eltValue.Index(i).Set(value) + } } return eltValue, nil diff --git a/parser/element_fill_test.go b/parser/element_fill_test.go index 1bfe62a..abffbb4 100644 --- a/parser/element_fill_test.go +++ b/parser/element_fill_test.go @@ -1395,6 +1395,37 @@ func TestFill(t *testing.T) { }, }}, }, + { + desc: "slice struct with slice", + rawSliceSeparator: "║", + node: &Node{ + Name: "traefik", + Kind: reflect.Pointer, + Children: []*Node{ + {Name: "Foo", FieldName: "Foo", Kind: reflect.Map, Children: []*Node{ + {Name: "Field1", FieldName: "Field1", RawValue: map[string]interface{}{ + "Field2": []interface{}{map[string]interface{}{"Values": "║24║foo║bar"}}, + }}, + {Name: "Field3", RawValue: map[string]interface{}{ + "Values": "║24║foo║bar", + }}, + }}, + }, + }, + element: &struct { + Foo map[string]interface{} + }{}, + expected: expected{element: &struct { + Foo map[string]interface{} + }{ + Foo: map[string]interface{}{ + "Field1": map[string]interface{}{"Field2": []interface{}{map[string]interface{}{"Values": []interface{}{"foo", "bar"}}}}, + "Field3": map[string]interface{}{ + "Values": []interface{}{"foo", "bar"}, + }, + }, + }}, + }, { desc: "slice pointer struct", node: &Node{