fix(prompts): clamp invalid page query values - #305
Conversation
Greptile SummaryThis PR fixes the public prompts listing endpoint so that malformed
Confidence Score: 5/5Safe to merge — the change is a minimal, targeted guard on a single query parameter with no side-effects on other code paths. The fix correctly handles all problematic inputs (zero, negative integers, NaN, non-numeric strings, and Infinity) and the offset computation is now guaranteed to be non-negative. Adding the explicit radix 10 to parseInt is also a correctness improvement. No existing behavior is altered for valid page values. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant GET /api/prompts
participant Supabase
Client->>GET /api/prompts: GET ?page=<value>
Note over GET /api/prompts: parsedPage = parseInt(page || "1", 10)
Note over GET /api/prompts: page = isFinite(parsedPage) && parsedPage > 0 ? parsedPage : 1
Note over GET /api/prompts: offset = (page - 1) * 20 [always >= 0]
GET /api/prompts->>Supabase: .range(offset, offset + 19)
Supabase-->>GET /api/prompts: { data, count }
GET /api/prompts-->>Client: { listings, total, page, per_page }
Reviews (1): Last reviewed commit: "fix(prompts): clamp invalid page query v..." | Re-trigger Greptile |
Summary
Fixes #298.
Verification