Skip to content

Commit

Permalink
Fix near page indexes crashing on invalid page number
Browse files Browse the repository at this point in the history
... which can very plausibly occur when rows get removed

fixes  #1835
  • Loading branch information
exyi committed Aug 18, 2024
1 parent bf7ef61 commit 867508d
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public DistanceNearPageIndexesProvider(int distance)
/// <param name="pagingOptions">The settings for paging.</param>
public IList<int> GetIndexes(IPagingOptions pagingOptions)
{
var firstIndex = Math.Max(pagingOptions.PageIndex - distance, 0);
var lastIndex = Math.Min(pagingOptions.PageIndex + distance + 1, pagingOptions.PagesCount);
var count = pagingOptions.PagesCount;
var index = Math.Max(0, Math.Min(count - 1, pagingOptions.PageIndex)); // clamp index to be a valid page
var firstIndex = Math.Max(index - distance, 0);
var lastIndex = Math.Min(index + distance + 1, count);

return Enumerable
.Range(firstIndex, lastIndex - firstIndex)
Expand Down

0 comments on commit 867508d

Please sign in to comment.