Skip to content

Commit ebcc070

Browse files
fix: validate monthly badge dimensions
1 parent 42016b6 commit ebcc070

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

app/api/streak/route.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,17 @@ describe('GET /api/streak', () => {
184184
const textOutput = await response.text();
185185
expect(textOutput).toContain('<svg');
186186
});
187+
188+
it('returns 400 when org contains invalid characters', async () => {
189+
const response = await GET(
190+
makeRequest({ user: 'octocat', org: 'invalid_org_name_with_spaces' })
191+
);
192+
const body = await response.json();
193+
194+
expect(response.status).toBe(400);
195+
expect(body.details.fieldErrors.org[0]).toBe('Invalid organization name format');
196+
expect(getOrgDashboardData).not.toHaveBeenCalled();
197+
});
187198
});
188199

189200
describe('successful response', () => {

lib/validations.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,16 @@ export const streakParamsSchema = z.object({
181181
grace: z.string().optional().transform(toGraceValue).default(1),
182182
mode: z.enum(['commits', 'loc']).catch('commits').default('commits'),
183183
repo: z.string().optional(),
184-
org: z.string().optional(),
184+
org: z
185+
.string()
186+
.optional()
187+
.refine(
188+
(val) => {
189+
if (!val) return true;
190+
return /^[a-zA-Z0-9](?:[a-zA-Z0-9]|-(?=[a-zA-Z0-9]))*$/.test(val);
191+
},
192+
{ message: 'Invalid organization name format' }
193+
),
185194
labels: z.string().optional().transform(toBooleanFlag),
186195
labelColor: z
187196
.string()

0 commit comments

Comments
 (0)