Skip to content

Commit e635e85

Browse files
fix: resolve validation syntax error
1 parent ebcc070 commit e635e85

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

lib/validations.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,18 @@ describe('streakParamsSchema — size fallback behavior', () => {
427427
}
428428
});
429429

430+
it('should fail when org contains invalid characters', () => {
431+
const result = streakParamsSchema.safeParse({
432+
user: 'octocat',
433+
org: 'invalid_org_name_with_spaces',
434+
});
435+
436+
expect(result.success).toBe(false);
437+
if (!result.success) {
438+
expect(result.error.flatten().fieldErrors.org?.[0]).toBe('Invalid organization name format');
439+
}
440+
});
441+
430442
it('should keep org undefined when omitted', () => {
431443
const result = streakParamsSchema.safeParse({
432444
user: 'octocat',

lib/validations.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,11 @@ export const streakParamsSchema = z.object({
183183
repo: z.string().optional(),
184184
org: z
185185
.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-
),
186+
.max(39, { message: 'Organization name cannot exceed 39 characters' })
187+
.regex(/^[a-zA-Z0-9](?:[a-zA-Z0-9]|-(?=[a-zA-Z0-9]))*$/, {
188+
message: 'Invalid organization name format',
189+
})
190+
.optional(),
194191
labels: z.string().optional().transform(toBooleanFlag),
195192
labelColor: z
196193
.string()

0 commit comments

Comments
 (0)