fix: validate limit/offset query params on intent listing - #158
Open
Phantomcall wants to merge 1 commit into
Open
fix: validate limit/offset query params on intent listing#158Phantomcall wants to merge 1 commit into
Phantomcall wants to merge 1 commit into
Conversation
- Add ListIntentsDto with @ISINT()/@min()/@max() validators for limit and offset - Move state/user/chain filters into the DTO as optional string fields - Replace raw parseInt with DTO-backed validation, eliminating NaN silently corrupting pagination - Add e2e tests asserting non-numeric limit/offset returns 400 Closes stellar-vortex-protocol#64
|
@Phantomcall 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.
PR Description: Fix Pagination NaN Bug in IntentsController.list()
Issue Reference
Summary
IntentsController.list()was usingparseInt()on raw query parameters (limitRaw,offsetRaw) without any validation. When a non-numeric value was provided (e.g.,?limit=abc),parseInt()returnedNaN, which silently corrupted the pagination slice (intents.slice(offset, offset + limit)) instead of returning a clear 400 error.Changes
New File:
src/intents/dto/list-intents.dto.tsIntroduced a typed DTO for list query parameters using
class-validatordecorators consistent with the rest of the codebase:limit:@IsInt(),@Min(1),@Max(100)— ensures the value is a valid integer between 1 and 100offset:@IsInt(),@Min(0)— ensures the value is a valid non-negative integerstate,user,chain:@IsOptional(),@IsString()— optional string filtersModified File:
src/intents/intents.controller.tslist()method signature from individual@Query()parameters to a single@Query() dto: ListIntentsDtoMath.min(parseInt(limitRaw, 10), 100)andparseInt(offsetRaw, 10)withdto.limitanddto.offsetValidationPipe(configured inmain.tswithwhitelist: true, transform: true) automatically validates the DTO and returns a 400 response with detailed error information when validation failsModified File:
test/intents.e2e-spec.tsAdded two new e2e tests:
GET /api/v1/intents with non-numeric limit returns 400— Asserts that?limit=abcreturns HTTP 400 witherror: "Validation failed"and an array ofdetailsGET /api/v1/intents with non-numeric offset returns 400— Asserts that?offset=xyzreturns HTTP 400 witherror: "Validation failed"and an array ofdetailsVerification
npm run lintpassesnpm run typecheckpassesnpm testpassesnpm run test:e2epasses (new e2e tests for non-numeric limit/offset)Acceptance Criteria
@IsInt()/@Min()/@Max()validatorslimitquery param returns 400, not a silently broken pageoffsetquery param returns 400, not a silently broken page