Skip to content

Fix /api/bounties pagination defaults - #300

Merged
ralyodio merged 1 commit into
profullstack:masterfrom
TheDerbiedOne:fix/bounties-pagination-validation
May 29, 2026
Merged

Fix /api/bounties pagination defaults#300
ralyodio merged 1 commit into
profullstack:masterfrom
TheDerbiedOne:fix/bounties-pagination-validation

Conversation

@TheDerbiedOne

Copy link
Copy Markdown
Contributor

Fixes #289.

  • Treat non-numeric or non-positive limit as the existing default (50), while keeping the max cap of 100.
  • Treat non-numeric or non-positive page as page 1.
  • Add a focused Vitest for limit=0, negative values, non-numeric input, and limit>100.

Tested: npm run test:run -- src/app/api/bounties/route.test.ts (installed with npm install --ignore-scripts to avoid a missing pnpm postinstall in this environment).

@greptile-apps

greptile-apps Bot commented May 29, 2026

Copy link
Copy Markdown

Greptile Summary

This PR tightens the limit and page parameter parsing in GET /api/bounties so that zero, negative, NaN, and non-numeric values all fall back to safe defaults (50 and 1 respectively), and adds a matching Vitest suite to prove the behaviour.

  • route.ts: replaces Number(param || fallback) (which left limit=0 and page=NaN silently through) with Number.isFinite + > 0 guards and a Math.floor normalisation before the 100-cap is applied.
  • route.test.ts: four focused cases — zero limit, negative page, over-cap limit (101 → 100), and fully non-numeric inputs — each asserting the exact range() call made to Supabase.

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to input parsing, the new logic is correct for all edge cases, and the tests validate each one.

The guard logic (Number.isFinite && > 0) correctly handles null, empty string, zero, negative, NaN, Infinity, and fractional inputs. The Math.floor normalisation and the 100-cap are applied in the right order. All four new tests assert the exact range() call arguments, which are the direct output of the fixed parsing. No pre-existing code paths are modified.

No files require special attention.

Important Files Changed

Filename Overview
src/app/api/bounties/route.ts Replaces the old numeric coercion for limit/page with explicit isFinite+positive guards and Math.floor, correctly handling null, zero, negative, and NaN inputs.
src/app/api/bounties/route.test.ts New Vitest file covering zero limit, negative page, over-cap limit (101), and non-numeric inputs — all assertions match the updated route logic.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[GET /api/bounties] --> B[Read limit param]
    B --> C{isFinite AND > 0?}
    C -- No --> D[limitCandidate = 50 default]
    C -- Yes --> E[limitCandidate = Math.floor limitRaw]
    D --> F[limit = Math.min limitCandidate, 100]
    E --> F
    F --> G[Read page param]
    G --> H{isFinite AND > 0?}
    H -- No --> I[page = 1]
    H -- Yes --> J[page = Math.floor pageRaw]
    I --> K[offset = page-1 × limit]
    J --> K
    K --> L[supabase .range offset, offset+limit-1]
Loading

Reviews (1): Last reviewed commit: "Fix /api/bounties pagination defaults" | Re-trigger Greptile

@ralyodio
ralyodio merged commit ce0fc27 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.

Bounties list accepts invalid pagination ranges

3 participants