refactor(calculate-version): 將驗證常數抽離為具名常數

- config 將每段長度上限與允許字元抽為 MAX_REPO_NAME_LENGTH / REPO_SEGMENT_PATTERN(regex 提升至模組層級,避免每次重編譯)
- releases 將片段截斷長度抽為 API_ERROR_SNIPPET_LENGTH

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jeffery
2026-06-26 14:11:36 +08:00
co-authored by Claude Opus 4.8
parent 8ee3638be5
commit d8a86e90ea
2 changed files with 11 additions and 4 deletions
+7 -3
View File
@@ -55,12 +55,16 @@ function assertHttpUrl(name, value) {
}
}
// 驗證 repository 為 owner/repo 格式(僅允許字母數字與 . _ -,且拒絕 . 與 .. 路徑穿越段
// repository 每段名稱的最大長度與允許字元(字母數字與 . _ -
const MAX_REPO_NAME_LENGTH = 100;
const REPO_SEGMENT_PATTERN = /^[A-Za-z0-9._-]+$/;
// 驗證 repository 為 owner/repo 格式(拒絕 . 與 .. 路徑穿越段、空段、過長或含非法字元的段)
function assertRepository(name, value) {
const parts = value.split('/');
const isRepoFormatValid = parts.length === 2
&& parts.every((part) => part.length > 0 && part.length <= 100
&& /^[A-Za-z0-9._-]+$/.test(part)
&& parts.every((part) => part.length > 0 && part.length <= MAX_REPO_NAME_LENGTH
&& REPO_SEGMENT_PATTERN.test(part)
&& part !== '.' && part !== '..');
if (!isRepoFormatValid) {
throw new Error(`${name} 格式錯誤,必須為 owner/repo`);