Skip to content

Commit

Permalink
Merge pull request #1847 from riganti/fix/near-page-index-OOR-v5
Browse files Browse the repository at this point in the history
Fix near page indexes crashing on invalid page number
  • Loading branch information
exyi authored Aug 17, 2024
2 parents d824028 + ba42313 commit 2bbf954
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Framework/Core/Controls/Options/PagingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ public virtual IList<int> GetNearPageIndexes()
/// </summary>
protected virtual IList<int> GetDefaultNearPageIndexes(int distance)
{
var firstIndex = Math.Max(PageIndex - distance, 0);
var lastIndex = Math.Min(PageIndex + distance + 1, PagesCount);
var count = this.PagesCount;
var index = Math.Max(0, Math.Min(count - 1, 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)
.ToList();
Expand Down

0 comments on commit 2bbf954

Please sign in to comment.