fix(pagination): handle out-of-bounds slicing in pagination
Ensure the pagination function correctly handles out-of-bounds indices when slicing items. Update the slice logic to prevent slice bounds errors and add a test case for better coverage of edge cases.
This commit is contained in:
+1
-1
@@ -87,7 +87,7 @@ func GetPage[T any](items []T, first *int, after *string, last *int, before *str
|
||||
sIx = f
|
||||
eIx = idx
|
||||
}
|
||||
page := items[sIx:eIx]
|
||||
page := items[sIx:min(eIx, len(items))]
|
||||
return page, PageInfo{
|
||||
StartCursor: ptr(EncodeCursor(fn(page[0]))),
|
||||
HasNextPage: eIx < len(items),
|
||||
|
||||
Reference in New Issue
Block a user