Commit 09caff5
authored
fix(api): reject reversed custom streak date ranges (JhaSourav07#1644)
## Description
Fixes JhaSourav07#1643
## Pillar
- [x] 🛠️ Other (Bug fix, refactoring, docs)
## What changed
The custom `from` and `to` parameters on `/api/streak` were validated
independently, so a reversed range such as
`from=2025-12-31&to=2025-01-01` passed schema validation and reached the
GitHub fetch path.
This PR adds object-level validation to `streakParamsSchema` so requests
with both dates present must satisfy:
```ts
Date.parse(from) <= Date.parse(to)
```
If the range is reversed, the route now returns a 400 validation
response before making any GitHub API request.
I also added a route regression test that verifies the reversed range is
rejected and `fetchGitHubContributions` is not called.
This is a GSSoC 2026 API bug fix contribution. Please add the relevant
GSSoC labels if they are missing.
## Visual Preview
N/A — this is API validation behavior.
## Local checks
```bash
npm run format:check
npm run lint
npm run test -- app/api/streak/route.test.ts
```
`npm run lint` reports one existing warning in
`components/ReturnToTop.test.tsx`; there are no lint errors.
## Checklist before requesting a review:
- [x] I have read the `CONTRIBUTING.md` file.
- [x] I have tested these changes locally.
- [x] I have run `npm run format` and `npm run lint` locally and
resolved all errors.
- [x] My commit follows the Conventional Commits format.
- [x] I have updated `README.md` if I added a new theme or URL
parameter.
- [x] I have starred the repo.
- [x] I have made sure that I have only one commit to merge in this PR.
- [x] The SVG output matches the CommitPulse quality standard.3 files changed
Lines changed: 30 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
531 | 531 | | |
532 | 532 | | |
533 | 533 | | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
534 | 547 | | |
535 | 548 | | |
536 | 549 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
153 | 161 | | |
154 | 162 | | |
155 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
246 | 254 | | |
247 | 255 | | |
248 | 256 | | |
| |||
0 commit comments