From ae3f10a397c2b03c08c052c62aa06cd42c845848 Mon Sep 17 00:00:00 2001 From: Michal Fojtik Date: Tue, 27 Jan 2015 17:43:46 +0100 Subject: [PATCH] Ensure the ptr is pointing to reflect.Slice in ExtractList --- pkg/runtime/helper.go | 4 ++++ pkg/runtime/helper_test.go | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/runtime/helper.go b/pkg/runtime/helper.go index b087d79464c..8681912a869 100644 --- a/pkg/runtime/helper.go +++ b/pkg/runtime/helper.go @@ -43,6 +43,10 @@ func GetItemsPtr(list Object) (interface{}, error) { } switch items.Kind() { case reflect.Interface, reflect.Ptr: + target := reflect.TypeOf(items.Interface()).Elem() + if target.Kind() != reflect.Slice { + return nil, fmt.Errorf("items: Expected slice, got %s", target.Kind()) + } return items.Interface(), nil case reflect.Slice: return items.Addr().Interface(), nil diff --git a/pkg/runtime/helper_test.go b/pkg/runtime/helper_test.go index f194b133af9..62984c3413c 100644 --- a/pkg/runtime/helper_test.go +++ b/pkg/runtime/helper_test.go @@ -86,14 +86,14 @@ func TestExtractListGeneric(t *testing.T) { } type fakePtrInterfaceList struct { - Items []*runtime.Object + Items *[]runtime.Object } func (f fakePtrInterfaceList) IsAnAPIObject() {} func TestExtractListOfInterfacePtrs(t *testing.T) { pl := &fakePtrInterfaceList{ - Items: []*runtime.Object{}, + Items: &[]runtime.Object{}, } list, err := runtime.ExtractList(pl) if err != nil {