Repository navigation
Treat missing query params as absent in clampInt - #32
Merged
Merged
Conversation
Number(null) and Number("") are both 0, which is finite, so a missing
or blank query param never reached the fallback — it clamped to `min`
instead.
Effects on the three call sites:
- handleHistory / handleStudents: GET /api/library/admin-history with
no limit returned 1 row and reported "limit": 1 rather than the
intended default of 100. (offset was harmless, since its min is 0.)
- handleStudentDetail: a request with no id clamped to 1 and quietly
returned student row 1, making the `if (!id)` "Student ID is
required." 400 guard unreachable.
Guard for null/blank before Number(), so absent params fall back and
explicitly supplied values clamp exactly as before.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
flow | 0df5908 | Aug 11 2026, 11:58 AM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
clampIntinsrc/admin.tsnever reached itsfallbackfor a missing query param:Number(null)andNumber("")are both0— finite — so theNumber.isFiniteguard passes and the value clamps up tomininstead of falling back.Impact
handleHistory/handleStudents— both callclampInt(url.searchParams.get("limit"), 1, 200, 100).GET /api/library/admin-historywith nolimitreturned 1 row and reported"limit": 1, rather than the intended default of 100. (offsetshares the bug but is harmless there, since itsminis0.)handleStudentDetail— callsclampInt(url.searchParams.get("id"), 1, 1000000000, 0)and thenif (!id) return json({ error: "Student ID is required." }, 400). A request with noidclamped to1and quietly returned student row 1, making that 400 guard unreachable.The manage UI always sends an explicit
limit, so the pagination side only affected direct API callers. ThehandleStudentDetailguard was reachable by anyone omittingid.Fix
Guard for null/blank before
Number():src/admin.tsholds the only definition ofclampInt—src/library.tshas no copy. The one adjacent pattern,retryPendingSheetEvents, clamps an already-numericlimitand both callers pass a literal25, so no query-string path reaches it.Verification
npx tsc --noEmitclean. Exercising the patched function body across the three call-site signatures:limit(1, 200, 100)offset(0, 100000, 0)id(1, 1e9, 0)null""/" ""abc""50""999""0"/"-5"Explicitly supplied values clamp exactly as before; only the absent/blank case changed.
🤖 Generated with Claude Code