@@ -5,6 +5,7 @@ import { createApiKeyForEnv, createPkApiKeyForEnv } from "~/models/api-key.serve
55import { logger } from "./logger.server" ;
66import { getLimit } from "./platform.v3.server" ;
77import { type CreateBranchOptions } from "~/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.branches/route" ;
8+ import { isValidGitBranchName } from "~/v3/validGitBranch" ;
89
910export class UpsertBranchService {
1011 #prismaClient: PrismaClient ;
@@ -167,37 +168,6 @@ export async function checkBranchLimit(
167168 } ;
168169}
169170
170- export function isValidGitBranchName ( branch : string ) : boolean {
171- // Must not be empty
172- if ( ! branch ) return false ;
173-
174- // Disallowed characters: space, ~, ^, :, ?, *, [, \
175- if ( / [ \~ \^ : \? \* \[ \\ ] / . test ( branch ) ) return false ;
176-
177- // Disallow ASCII control characters (0-31) and DEL (127)
178- for ( let i = 0 ; i < branch . length ; i ++ ) {
179- const code = branch . charCodeAt ( i ) ;
180- if ( ( code >= 0 && code <= 31 ) || code === 127 ) return false ;
181- }
182-
183- // Cannot start or end with a slash
184- if ( branch . startsWith ( "/" ) || branch . endsWith ( "/" ) ) return false ;
185-
186- // Cannot have consecutive slashes
187- if ( branch . includes ( "//" ) ) return false ;
188-
189- // Cannot contain '..'
190- if ( branch . includes ( ".." ) ) return false ;
191-
192- // Cannot contain '@{'
193- if ( branch . includes ( "@{" ) ) return false ;
194-
195- // Cannot end with '.lock'
196- if ( branch . endsWith ( ".lock" ) ) return false ;
197-
198- return true ;
199- }
200-
201171export function sanitizeBranchName ( ref : string ) : string | null {
202172 if ( ! ref ) return null ;
203173 if ( ref . startsWith ( "refs/heads/" ) ) return ref . substring ( "refs/heads/" . length ) ;
0 commit comments