-
Notifications
You must be signed in to change notification settings - Fork 32
fix(pages): clamp public listing page values #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
454e104
6d502ef
780cf5a
79874ff
5cf361b
8af598e
c78c859
83e2c58
9d51c28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { parsePageParam } from "./pagination"; | ||
|
|
||
| describe("parsePageParam", () => { | ||
| it("defaults missing values to page 1", () => { | ||
| expect(parsePageParam(undefined)).toBe(1); | ||
| expect(parsePageParam(null)).toBe(1); | ||
| expect(parsePageParam("")).toBe(1); | ||
| }); | ||
|
|
||
| it("clamps invalid low values to page 1", () => { | ||
| expect(parsePageParam("-1")).toBe(1); | ||
| expect(parsePageParam("0")).toBe(1); | ||
| expect(parsePageParam("abc")).toBe(1); | ||
| }); | ||
|
|
||
| it("truncates fractional page values", () => { | ||
| expect(parsePageParam("2.9")).toBe(2); | ||
| }); | ||
|
|
||
| it("caps very large page values", () => { | ||
| expect(parsePageParam("999999999")).toBe(100_000); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| const DEFAULT_MAX_PAGE = 100_000; | ||
|
|
||
| export function parsePageParam( | ||
| value: string | null | undefined, | ||
| maxPage = DEFAULT_MAX_PAGE | ||
| ) { | ||
| const parsed = parseInt(value || "1", 10); | ||
| return Number.isFinite(parsed) | ||
| ? Math.min(Math.max(parsed, 1), maxPage) | ||
| : 1; | ||
| } | ||
|
Comment on lines
+1
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every non-ASCII decorative character in the PR's changed files has been replaced with a mojibake equivalent:
≈→≈,—→â€",→→â†',✕→✕,⚡→âš¡. These are the raw UTF-8 byte sequences of the originals re-encoded as Latin-1 then stored back as UTF-8 — a classic double-encoding error. A browser serving the UTF-8 page will render these literally (e.g. showing "â€" 50 âš¡" instead of "— 50 ⚡"), breaking visible content for all affected listing pages. The same corruption appears insrc/app/directory/page.tsx,src/app/for-hire/[[...tags]]/page.tsx,src/app/gigs/[[...tags]]/page.tsx,src/app/mcp/page.tsx,src/app/prompts/page.tsx, andsrc/app/skills/page.tsx— the pattern is present throughout the PR.