From 283de8fa1982521684f90d69e12a14ce64af18e3 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 29 Apr 2025 22:37:43 +0300 Subject: [PATCH] handlers: fix panic in search, fix #300 This logic adds an implicit first attribute if it's missing from the original request. It assumes that there is always at least one filter present which is no longer true after 706d7d4bf01b2b53dd6ee97bda153e624f0e0537. Now the code is adjusted for that. Signed-off-by: Roman Khimov --- handlers/objects.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/handlers/objects.go b/handlers/objects.go index 75adb93..0e3f5d7 100644 --- a/handlers/objects.go +++ b/handlers/objects.go @@ -476,8 +476,13 @@ func (a *RestAPI) V2SearchObjects(ctx echo.Context, containerID apiserver.Contai cursor string opts client.SearchObjectsOptions - searchHeader = filters[0].Header() + returningAttributes = make([]string, 0, len(searchFilters.Attributes)+1) + searchHeader string ) + if len(filters) > 0 { + searchHeader = filters[0].Header() + returningAttributes = append(returningAttributes, searchHeader) + } for i, attr := range searchFilters.Attributes { if attr == searchHeader { @@ -486,7 +491,7 @@ func (a *RestAPI) V2SearchObjects(ctx echo.Context, containerID apiserver.Contai } } - returningAttributes := append([]string{searchHeader}, searchFilters.Attributes...) + returningAttributes = append(returningAttributes, searchFilters.Attributes...) if params.Cursor != nil { cursor = *params.Cursor }