Skip to content

fix(prompts): clamp invalid page query values - #305

Merged
ralyodio merged 1 commit into
profullstack:masterfrom
Jorel97:codex/fix-prompts-page-clamp-298
May 29, 2026
Merged

fix(prompts): clamp invalid page query values#305
ralyodio merged 1 commit into
profullstack:masterfrom
Jorel97:codex/fix-prompts-page-clamp-298

Conversation

@Jorel97

@Jorel97 Jorel97 commented May 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • clamps the public prompts list page query to a minimum of 1
  • keeps invalid, zero, negative, or NaN page values from producing negative Supabase ranges

Fixes #298.

Verification

  • Inspected src/app/api/prompts/route.ts and confirmed offset now derives from a positive page number.
  • Full local test suite not run in this environment because the repo was updated through the GitHub API without a full dependency checkout.

@greptile-apps

greptile-apps Bot commented May 29, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes the public prompts listing endpoint so that malformed page query parameters (zero, negative, NaN, or non-numeric strings) no longer produce negative Supabase range offsets. The two-line change adds an explicit radix to parseInt and clamps the result to a minimum of 1 before computing the offset.

  • parseInt now always uses radix 10, eliminating any implicit octal/hex parsing ambiguity.
  • A Number.isFinite(parsedPage) && parsedPage > 0 guard falls back to page 1 for any out-of-range value, making the offset computation safe in all invalid-input cases.

Confidence Score: 5/5

Safe 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

Filename Overview
src/app/api/prompts/route.ts Adds radix to parseInt and clamps parsed page value to ≥1, preventing negative Supabase range offsets from zero, negative, or non-numeric page query params.

Sequence Diagram

sequenceDiagram
    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 }
Loading

Reviews (1): Last reviewed commit: "fix(prompts): clamp invalid page query v..." | Re-trigger Greptile

@ralyodio
ralyodio merged commit 9ac5b09 into profullstack:master May 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prompts list accepts invalid page numbers

2 participants