Skip to content

fix(feed): clamp invalid pagination ranges - #314

Merged
ralyodio merged 1 commit into
profullstack:masterfrom
Jorel97:codex/fix-feed-pagination-313
May 29, 2026
Merged

fix(feed): clamp invalid pagination ranges#314
ralyodio merged 1 commit into
profullstack:masterfrom
Jorel97:codex/fix-feed-pagination-313

Conversation

@Jorel97

@Jorel97 Jorel97 commented May 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #313.

Summary

  • parse feed page and limit query params with bounded integer parsing before validation
  • prevent fractional, non-finite, or extreme values from reaching Supabase .range()
  • add regression coverage for fractional and non-finite pagination inputs

Tests

  • Not run locally; dependencies are not installed in this workspace checkout.

@greptile-apps

greptile-apps Bot commented May 29, 2026

Copy link
Copy Markdown

Greptile Summary

This PR replaces the bare Number(param) || default pagination pattern with a dedicated parsePaginationParam helper that validates finiteness, truncates fractions, and clamps to explicit [min, max] bounds before values reach Supabase .range().

  • parsePaginationParam uses Number() (not parseInt) so mixed strings like "3abc" produce NaN and fall back to the default rather than silently advancing to page 3.
  • Three new regression tests verify fractional, non-finite, and mixed-alpha inputs; all expected range() call arguments and response pagination fields are arithmetically correct.

Confidence Score: 5/5

Safe to merge — the change is a narrow, self-contained fix to pagination parsing with no impact on auth, data mutation, or schema.

The helper correctly handles every problematic input class (null, empty, fractional, non-finite, mixed alpha-numeric) through a single, well-ordered chain of Number() → isFinite → Math.trunc → clamp. The new tests directly verify all three regression cases and their expected Supabase range() arguments. No pre-existing issues are exposed by this change.

No files require special attention.

Important Files Changed

Filename Overview
src/app/api/feed/route.ts Introduces parsePaginationParam helper that uses Number() + isFinite + Math.trunc + clamping to replace bare Number()
src/app/api/feed/route.test.ts Adds three regression tests covering fractional, non-finite (Infinity/NaN), and mixed-alpha ("3abc", "7px") inputs; expected range() offsets and response pagination fields are all arithmetically correct.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["GET /api/feed\n?page=X & ?limit=Y"] --> B["parsePaginationParam(value, default, min, max)"]
    B --> C{"value is null?"}
    C -- "yes (??)" --> D["use defaultValue"]
    C -- "no" --> E["Number(value)"]
    D --> E
    E --> F{"isFinite(parsed)?"}
    F -- "false\n(NaN, Infinity, -Infinity)" --> G["return defaultValue"]
    F -- "true" --> H["Math.trunc(parsed)"]
    H --> I["Math.max(truncated, min)"]
    I --> J["Math.min(result, max)"]
    J --> K["clamped integer → feedFiltersSchema.safeParse"]
    K --> L["offset = (page-1) * limit"]
    L --> M["supabase .range(offset, offset+limit-1)"]
Loading

Reviews (2): Last reviewed commit: "fix(feed): clamp invalid pagination rang..." | Re-trigger Greptile

Comment thread src/app/api/feed/route.ts Outdated
@Jorel97
Jorel97 force-pushed the codex/fix-feed-pagination-313 branch from e499ad1 to edf4d7a Compare May 29, 2026 19:31
@ralyodio
ralyodio merged commit e001317 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.

Feed endpoint accepts fractional pagination ranges

2 participants