const BRANCH_PATTERN = /^[0-9A-Za-z._/-]+$/u; const COMMIT_PATTERN = /^[0-9a-fA-F]{7,40}$/u; export function validateBranch(value: string) { const branch = value.trim(); if (!branch) { return '请输入分支名'; } if ( branch.length > 200 || !BRANCH_PATTERN.test(branch) || branch.startsWith('/') || branch.endsWith('/') || branch.includes('..') ) { return '分支名格式不正确'; } return ''; } export function validateCommitHash(value: string) { const commitHash = value.trim(); if (commitHash && !COMMIT_PATTERN.test(commitHash)) { return 'Commit Hash 需为 7 到 40 位十六进制字符'; } return ''; }