fix(calculate-version): 強化片段截斷與 repository 驗證健全性
- releases 改以 Array.from 依字元截斷回應片段,避免拆分多位元組字元造成亂碼,並標記片段內容 - config assertRepository 加入每段長度上限,並將 valid 更名為語義明確的 isRepoFormatValid Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
32e528988b
commit
da83f4fc30
+5
-3
@@ -58,9 +58,11 @@ function assertHttpUrl(name, value) {
|
|||||||
// 驗證 repository 為 owner/repo 格式(僅允許字母數字與 . _ -,且拒絕 . 與 .. 路徑穿越段)
|
// 驗證 repository 為 owner/repo 格式(僅允許字母數字與 . _ -,且拒絕 . 與 .. 路徑穿越段)
|
||||||
function assertRepository(name, value) {
|
function assertRepository(name, value) {
|
||||||
const parts = value.split('/');
|
const parts = value.split('/');
|
||||||
const valid = parts.length === 2
|
const isRepoFormatValid = parts.length === 2
|
||||||
&& parts.every((part) => /^[A-Za-z0-9._-]+$/.test(part) && part !== '.' && part !== '..');
|
&& parts.every((part) => part.length > 0 && part.length <= 100
|
||||||
if (!valid) {
|
&& /^[A-Za-z0-9._-]+$/.test(part)
|
||||||
|
&& part !== '.' && part !== '..');
|
||||||
|
if (!isRepoFormatValid) {
|
||||||
throw new Error(`${name} 格式錯誤,必須為 owner/repo`);
|
throw new Error(`${name} 格式錯誤,必須為 owner/repo`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -63,9 +63,9 @@ async function fetchReleases(baseUrl, options = {}) {
|
|||||||
try {
|
try {
|
||||||
pageJson = JSON.parse(text);
|
pageJson = JSON.parse(text);
|
||||||
} catch {
|
} catch {
|
||||||
// 附上截斷的回傳內容片段,便於除錯回傳格式異常
|
// 以字元(而非 UTF-16 碼元)截斷回傳內容片段,避免拆分多位元組字元造成亂碼
|
||||||
const snippet = text.slice(0, 200);
|
const contentSnippet = Array.from(text).slice(0, 200).join('');
|
||||||
throw new Error(`release API 回傳資料無法解析 (page=${page}): ${snippet}`);
|
throw new Error(`release API 回傳資料無法解析 (page=${page}),回應內容片段:「${contentSnippet}」`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pageJson === null) {
|
if (pageJson === null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user