fix(feed): clamp invalid pagination ranges - #314
Conversation
Greptile SummaryThis PR replaces the bare
Confidence Score: 5/5Safe 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
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)"]
Reviews (2): Last reviewed commit: "fix(feed): clamp invalid pagination rang..." | Re-trigger Greptile |
e499ad1 to
edf4d7a
Compare
Fixes #313.
Summary
pageandlimitquery params with bounded integer parsing before validation.range()Tests