Repository navigation
fix(backend): allow negative page values in PaginationQuerySchema for downstream clamping - #1490
Merged
Junirezz merged 2 commits intoOct 3, 2026
Conversation
… downstream clamping PaginationQuerySchema.page rejected page=-1 due to a positive-integer-only regex, causing validation errors (400) even though parsePaginationQuery safely clamps non-positive pages to 1. Allow negative integers in page validation so the downstream parser handles pagination gracefully.
|
@CathyZaks Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
PaginationQuerySchema.pagevalidation to allow negative integer strings (such aspage=-1), allowing the downstreamparsePaginationQueryfunction to safely clamp them to page 1.Problem
PaginationQuerySchema.pageused the regex/^\d+$/with the validation error message"page must be a positive integer". When requests with negative page values (such asGET /api/transactions?page=-1) were validated by endpoints usingPaginationQuerySchemaorTransactionListQuerySchema, the request failed with a 400 Validation Error. However, the downstream pagination parser (parsePaginationQuery) already safely handles and clamps non-positive or negative page inputs to page1(returning 200). The validation schema was unnecessarily stricter than the downstream parser it feeds.Solution
Update
PaginationQuerySchema.pageto validate against/^-?\d+$/(page must be an integer), permitting negative integers like-1to pass schema validation and reachparsePaginationQueryfor safe clamping to1.Changes
backend/src/types/validation.ts:Update
pagefield regex from/^\d+$/to/^-?\d+$/and adjust error message to'page must be an integer'.backend/src/__tests__/requestValidation.test.ts:Add unit tests verifying
PaginationQuerySchema.safeParseaccepts negative page values likepage: '-1'for downstream clamping and rejects non-numeric page values likepage: 'abc'.Testing
requestValidation.test.ts: all 8 tests passing.Closes #1367