File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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' , ( ) => {
Original file line number Diff line number Diff 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 - z A - Z 0 - 9 ] (?: [ a - z A - Z 0 - 9 ] | - (? = [ a - z A - Z 0 - 9 ] ) ) * $ / . test ( val ) ;
191+ } ,
192+ { message : 'Invalid organization name format' }
193+ ) ,
185194 labels : z . string ( ) . optional ( ) . transform ( toBooleanFlag ) ,
186195 labelColor : z
187196 . string ( )
You can’t perform that action at this time.
0 commit comments