Skip to content

fix(directory): clamp invalid page query values - #307

Merged
ralyodio merged 2 commits into
profullstack:masterfrom
Jorel97:codex/fix-directory-page-clamp-296
May 29, 2026
Merged

fix(directory): clamp invalid page query values#307
ralyodio merged 2 commits into
profullstack:masterfrom
Jorel97:codex/fix-directory-page-clamp-296

Conversation

@Jorel97

@Jorel97 Jorel97 commented May 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • clamps the directory list page query to a minimum of 1
  • prevents negative Supabase ranges for invalid, zero, negative, or NaN page values

Fixes #296.

Verification

  • Inspected src/app/api/directory/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 a bug where invalid page query values (negative, zero, NaN, or non-numeric) could produce a negative Supabase .range() offset. The fix parses the value with an explicit radix-10 parseInt, guards against non-finite results, and clamps the value to [1, 10_000].

  • The lower-bound guard replaces the old bare parseInt call and correctly funnels NaN, zero, and negative values to page 1.
  • A new MAX_DIRECTORY_PAGE constant caps the upper bound at 10 000 pages, preventing arbitrarily large offsets that would silently return empty results or trigger a PostgREST error.

Confidence Score: 5/5

The change is minimal and correctly handles all invalid page inputs without touching any other logic.

The three-line modification is tightly scoped to page-value parsing. All invalid inputs (NaN, zero, negative) now fall back to 1, and an explicit upper cap prevents runaway offsets. The rest of the GET handler and the entire POST handler are untouched.

No files require special attention.

Important Files Changed

Filename Overview
src/app/api/directory/route.ts Adds lower- and upper-bound clamping for the page query parameter — invalid/zero/negative/NaN values fall back to 1, values above 10 000 are capped; also fixes missing radix on parseInt.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[GET /api/directory?page=X] --> B["parseInt(raw || '1', 10)"]
    B --> C{Number.isFinite AND > 0?}
    C -- No --> D[page = 1]
    C -- Yes --> E["Math.min(parsedPage, 10_000)"]
    E --> F[page = clamped value]
    D --> G["offset = (page - 1) * 20"]
    F --> G
    G --> H["supabase.range(offset, offset + 19)"]
    H --> I[Return listings JSON]
Loading

Reviews (2): Last reviewed commit: "fix(directory): cap extreme page query v..." | Re-trigger Greptile

Comment thread src/app/api/directory/route.ts Outdated
@ralyodio
ralyodio merged commit 42d849c 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.

Directory listing accepts invalid page numbers

2 participants