Skip to content

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

Merged
ppetzold merged 6 commits intoppetzold:masterfrom
tejasdev:fix/issue-1103-incorrect-meta-when-out-of-bound
Mar 6, 2026
Merged

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

Conversation

@tejasdev
Copy link
Copy Markdown
Contributor

@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
Copy Markdown

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.

@tejasdev
Copy link
Copy Markdown
Contributor Author

tejasdev commented Feb 9, 2026

@ppetzold, any update on this PR?

@ppetzold ppetzold merged commit 99577b4 into ppetzold:master Mar 6, 2026
2 checks passed
@ppetzold
Copy link
Copy Markdown
Owner

ppetzold commented Mar 6, 2026

🎉 This PR is included in version 12.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect meta when page query param is out of bound

3 participants