Skip to content

fix: validate pagination parameters in city API to prevent NaN values#409

Open
vipul674 wants to merge 22 commits into
Ixotic27:mainfrom
vipul674:372-validate-city-api-pagination
Open

fix: validate pagination parameters in city API to prevent NaN values#409
vipul674 wants to merge 22 commits into
Ixotic27:mainfrom
vipul674:372-validate-city-api-pagination

Conversation

@vipul674

@vipul674 vipul674 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Validates pagination parameters in GET /api/city to prevent NaN values from flowing into the Supabase query layer.

Added isNaN checks for from and to query parameters after parseInt. Returns a 400 error with a clear message if either value is invalid, instead of passing NaN to .range().

Related issue

Fixes #372

Screenshots

No visual changes — this is an API validation fix.

Checklist

  • npm run lint passes
  • Tested locally
  • No secrets or .env values committed
  • I acknowledge that an automated AI Reviewer will perform a preliminary review of this PR.
  • I have starred this repository! (We prioritize PRs and assignments for stargazers)

Add isNaN check for 'from' and 'to' query parameters before they
flow into the Supabase range call. Returns 400 error for invalid
values instead of passing NaN to the database layer.

Fixes Ixotic27#372
@vercel

vercel Bot commented Jun 8, 2026

Copy link
Copy Markdown

@vipul674 is attempting to deploy a commit to the ixotic27-8245's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

👋 Hey @vipul674, welcome to The Leetcode City! 🎉

Thanks for opening your first pull request — this is a big deal and we appreciate the effort!

While you wait for a review, please double-check:

  • ✅ You've read the CONTRIBUTING.md checklist
  • npm run lint passes locally
  • ✅ Your PR description includes Fixes #<issue-number>

A maintainer will review your PR shortly. Hang tight! 🚀

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security Scan: Clean

No suspicious patterns detected. The official Copilot bot will provide detailed AI feedback shortly.

If you enjoyed contributing, please consider starring the repository!

@github-actions github-actions Bot added backend Backend/API related good first issue Good for newcomers Gssoc 26 Part of GirlScript Summer of Code 2026 gssoc:approved Approved GSSoC contribution level:beginner Beginner difficulty level type:bug Something isn't working as expected labels Jun 8, 2026
@vipul674

vipul674 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@Ixotic27 PR is ready for review.

Report

Issue

GET /api/city did not validate from and to query parameters. parseInt("abc", 10) returns NaN, and Math.max(0, NaN) is also NaN, which then flows into the Supabase .range() call.

Changes

  • src/app/api/city/route.ts: Added isNaN checks for both from and to after parsing. Returns 400 error with message for invalid values.

Fix Details

  • Parse raw values first into rawFrom and rawTo
  • Check isNaN(rawFrom) || isNaN(rawTo) before proceeding
  • Return { error: "Invalid pagination parameters: from and to must be numbers." } with status 400
  • Valid values proceed to Math.max/Math.min as before

Files Changed

  • src/app/api/city/route.ts (+12, -5)

Verification

  • Code compiles (syntax verified via diff review)
  • /api/city?from=abc&to=500 now returns 400 instead of passing NaN to database
  • Valid requests like /api/city?from=0&to=500 continue to work as before

@vercel

vercel Bot commented Jun 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
the-leetcode-city Ready Ready Preview, Comment Jun 8, 2026 4:41pm

@vipul674

vipul674 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@Ixotic27 All checks pass, please check and merge.

@github-actions github-actions Bot added the status:blocked This PR is blocked due to a failing CI check. label Jun 9, 2026
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🚨 Hey @vipul674, the CI Pipeline is failing on this PR and it has been marked as status:blocked.

🔍 What failed:

  • Production Build failed at step(s): Build

📋 Error Details (first 2):

Please fix the issues before this can be reviewed. Here's how:

1. Run checks locally before pushing:

npm run lint           # Run ESLint
npm run build          # Verify production build passes

2. Auto-fix common issues:

npm run lint -- --fix  # Auto-fix lint errors where possible

3. Check the full failure log here:
👉 View CI Run

Once you push a fix and the CI passes, the status:blocked label will be removed automatically. 💪

@github-actions github-actions Bot removed the status:blocked This PR is blocked due to a failing CI check. label Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend/API related good first issue Good for newcomers gssoc:approved Approved GSSoC contribution Gssoc 26 Part of GirlScript Summer of Code 2026 level:beginner Beginner difficulty level type:bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: City API can pass NaN pagination values to Supabase

2 participants