fix(gigs): cap page query values#347
Conversation
Greptile SummaryThis PR fixes oversized
Confidence Score: 5/5Safe to merge — the capping logic is correct, schema validation still provides the min/max guardrails, and the removed clampedLimit was fully redundant given upstream caps plus Zod constraints. The upstream Math.min caps for both page and limit are correctly implemented and consistent with schema constraints. Removing clampedLimit is safe because gigFiltersSchema enforces min(1) and max(50) on limit, so invalid values still result in a 400. The two new tests verify the correct Supabase range bounds and pagination metadata for oversized inputs. No current defects were found in the changed paths. No files require special attention beyond the minor constant-duplication note on route.ts. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[GET /api/gigs request] --> B[Parse searchParams]
B --> C["page = Math.min(Number(page) || 1, MAX_GIG_PAGE)"]
B --> D["limit = Math.min(Number(limit) || 20, MAX_GIG_LIMIT)"]
C --> E[gigFiltersSchema.safeParse]
D --> E
E -->|invalid| F[400 Bad Request]
E -->|valid| G[Build Supabase query]
G --> H["offset = Math.max(0, (page-1) * limit)"]
H --> I["query.range(offset, offset + limit - 1)"]
I --> J[Execute query]
J --> K["Return gigs + pagination {page, limit, total, totalPages}"]
Reviews (2): Last reviewed commit: "fix(gigs): cap page and limit values" | Re-trigger Greptile |
|
Addressed the Greptile pagination note in the latest commits. The route now caps both oversized page and limit values before range construction/metadata, and the test coverage includes both huge page and huge limit inputs. |
Fixes #346.
This caps huge
/api/gigs?page=...values before they are validated and used to build the Supabase range offset. Normal pages are unchanged, while oversized pages now use a safeMAX_GIG_PAGEvalue and return matching pagination metadata.I also added regression coverage for an oversized page value and the resulting
.range(...)bounds.Verification: local dependency install is unavailable in this workspace, so I validated the targeted source/test change and will follow the PR checks.