Skip to content

fix: handle out-of-bounds page parameter gracefully (#1103)#1119

Open
tejasdev wants to merge 6 commits intoppetzold:masterfrom
tejasdev:fix/issue-1103-incorrect-meta-when-out-of-bound
Open

fix: handle out-of-bounds page parameter gracefully (#1103)#1119
tejasdev wants to merge 6 commits intoppetzold:masterfrom
tejasdev:fix/issue-1103-incorrect-meta-when-out-of-bound

Conversation

@tejasdev
Copy link

@tejasdev tejasdev commented Jan 1, 2026

Description

Fixes out-of-bounds page parameter handling by clamping currentPage to valid range.

Changes

  • Clamp currentPage to range [1, totalPages]
  • Update links generation to use clamped currentPage
  • Add test coverage for edge cases

Related Issue

Closes #1103

Testing

  • Added new test cases for page > totalPages and page <= 0
  • All existing tests pass

- Clamp `currentPage` to valid range (1 to totalPages)
- Fix links generation to use clamped `currentPage`
- Prevent invalid `next` and `last` links when on last page
- Add tests for edge cases (page=0, page > totalPages)
Copilot AI review requested due to automatic review settings January 1, 2026 08:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes out-of-bounds page parameter handling by introducing a clamped currentPage value that constrains page numbers to the valid range [1, totalPages]. However, the implementation has critical issues with inconsistent application of the clamping logic.

Key Changes:

  • Introduced currentPage variable that clamps the page parameter to [1, totalPages]
  • Updated metadata to use clamped currentPage instead of raw page
  • Partially updated link generation to use clamped value (only for current link)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/paginate.ts Adds clamping logic for currentPage and updates meta/links to use it (lines 982, 989, 1014), plus formatting changes (lines 225-230)
src/paginate.spec.ts Adds test cases for out-of-bounds page parameter handling (lines 3138-3167) and additional link assertions (lines 3640-3641)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect meta when page query param is out of bound

1 participant