Skip to content

fix(tags): clamp zero and invalid popular-tags limit with parsePaginationParam#377

Open
Nexu0ps wants to merge 1 commit into
profullstack:masterfrom
Nexu0ps:fix/popular-tags-limit-clamp
Open

fix(tags): clamp zero and invalid popular-tags limit with parsePaginationParam#377
Nexu0ps wants to merge 1 commit into
profullstack:masterfrom
Nexu0ps:fix/popular-tags-limit-clamp

Conversation

@Nexu0ps
Copy link
Copy Markdown

@Nexu0ps Nexu0ps commented Jun 2, 2026

Fixes #360

Replaces the ad-hoc Math.min(Math.max(parseInt(...) || 50, 1), 200) with the shared parsePaginationParam helper so limit=0 clamps to 1, malformed values fall back to 50, and oversized values cap at 200.

Replaces ad-hoc Math.min/Math.max/parseInt with parsePaginationParam
so limit=0 clamps to 1, malformed values fall back to 50, and
oversized values cap at 200.

Fixes profullstack#360
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Jun 2, 2026

Greptile Summary

This PR refactors the limit parsing in the popular-tags API route, replacing the inline Math.min/Math.max/parseInt chain with the shared parsePaginationParam helper. Behavioral parity is preserved: null/empty falls back to 50, values below 1 clamp to 1, and values above 200 cap at 200.

  • The old parseInt-based path accepted partial strings like \"50abc\" as 50; Number() inside parsePaginationParam rejects them as NaN and returns the default instead — a stricter and arguably safer behavior.
  • The Math.trunc path in the helper mirrors parseInt's integer truncation for decimal inputs, so \"3.7\" still yields 3.

Confidence Score: 5/5

Safe to merge — the change is a one-line substitution with a well-tested shared helper and no logic is altered.

The only touched line swaps an inline clamping expression for parsePaginationParam, which has its own test file and produces identical or stricter output. The rest of the route is unchanged.

No files require special attention.

Important Files Changed

Filename Overview
src/app/api/tags/popular/route.ts Replaces inline limit-clamping expression with parsePaginationParam; logic is equivalent or stricter for malformed inputs. No other changes.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Route as GET /api/tags/popular
    participant parsePaginationParam
    participant Supabase

    Client->>Route: "GET /api/tags/popular?limit=<value>"
    Route->>parsePaginationParam: parsePaginationParam(value, 50, 1, 200)
    parsePaginationParam-->>Route: clamped limit (1-200, default 50)
    Route->>Supabase: "SELECT skills_required FROM gigs WHERE status='active'"
    Supabase-->>Route: gigs[]
    Route->>Supabase: SELECT tag FROM tag_follows
    Supabase-->>Route: follows[]
    Route->>Route: build tag counts, sort, slice(0, limit)
    Route-->>Client: "{ tags: [...] }"
Loading

Reviews (1): Last reviewed commit: "fix(tags): use parsePaginationParam to c..." | Re-trigger Greptile

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.

Clamp zero popular-tags limits instead of expanding to the default

1 participant