fix(search): clamp pagination bounds#325
Conversation
Greptile SummaryThis PR introduces a
Confidence Score: 5/5Safe to merge — the change is narrowly scoped to input parsing and all reachable edge cases are handled correctly. The parsePaginationParam helper correctly handles every relevant input class: null/empty/whitespace fall back to the default, fractional values are truncated, negatives are clamped to the minimum, huge-but-finite values (e.g. 1e308) are clamped to the maximum, and non-finite values (Infinity, NaN) fall back to the default via the isFinite guard. Offset arithmetic is unchanged and the two new tests verify the expected .range() arguments precisely. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["GET /api/search\n?page=X & limit=Y"] --> B["parsePaginationParam(X, 1, 1, 100_000)"]
B --> C{"value null\nor blank?"}
C -- yes --> D["parsed = Number(defaultValue)"]
C -- no --> E["parsed = Number(value)"]
D --> F{"Number.isFinite\n(parsed)?"}
E --> F
F -- no --> G["finiteValue = defaultValue"]
F -- yes --> H["finiteValue = parsed"]
G --> I["Math.trunc(finiteValue)"]
H --> I
I --> J["Math.max(result, min)"]
J --> K["Math.min(result, max)"]
K --> L["page in [1, 100_000]\nlimit in [1, 50]"]
L --> M["offset = (page - 1) x limit"]
M --> N["supabase .range(offset, offset + limit - 1)"]
Reviews (1): Last reviewed commit: "fix(search): clamp pagination bounds" | Re-trigger Greptile |
Summary
Fixes #324.
Testing