test: 整併測試至 app/test 並解決 AI 審查 findings #8
+7
-3
@@ -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) {
|
function assertRepository(name, value) {
|
||||||
|
|
|||||||
const parts = value.split('/');
|
const parts = value.split('/');
|
||||||
const isRepoFormatValid = parts.length === 2
|
const isRepoFormatValid = parts.length === 2
|
||||||
|
Ghost marked this conversation as resolved
gitea-actions
commented
嚴重等級:🟡 警告 **嚴重等級**:🟡 警告
**審查員**:Bard
**問題**:函數 `assertRepository` 命名較為通用,但其實際行為僅在驗證 Gitea 的 `owner/repo` 格式。命名未能直接體現其檢查邏輯與該領域規則。
**建議**:建議重新命名為 `assertGiteaRepositoryFormat`,讓開發者一眼就能看出該函數在檢查特定的 Gitea 倉庫格式規範。
|
|||||||
&& parts.every((part) => part.length > 0 && part.length <= 100
|
&& parts.every((part) => part.length > 0 && part.length <= MAX_REPO_NAME_LENGTH
|
||||||
&& /^[A-Za-z0-9._-]+$/.test(part)
|
&& REPO_SEGMENT_PATTERN.test(part)
|
||||||
&& part !== '.' && part !== '..');
|
&& part !== '.' && part !== '..');
|
||||||
if (!isRepoFormatValid) {
|
if (!isRepoFormatValid) {
|
||||||
throw new Error(`${name} 格式錯誤,必須為 owner/repo`);
|
throw new Error(`${name} 格式錯誤,必須為 owner/repo`);
|
||||||
|
|||||||
+4
-1
@@ -3,6 +3,9 @@
|
|||||||
// 每頁取得的 release 筆數
|
// 每頁取得的 release 筆數
|
||||||
const RELEASES_PER_PAGE = 10;
|
const RELEASES_PER_PAGE = 10;
|
||||||
|
|
||||||
|
// JSON 解析失敗時,附在錯誤訊息中的回應內容片段最大字元數
|
||||||
|
const API_ERROR_SNIPPET_LENGTH = 200;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 以分頁方式取得指定 Gitea repo 的所有 release,並回傳合併後的陣列。
|
* 以分頁方式取得指定 Gitea repo 的所有 release,並回傳合併後的陣列。
|
||||||
*
|
*
|
||||||
@@ -64,7 +67,7 @@ async function fetchReleases(baseUrl, options = {}) {
|
|||||||
pageJson = JSON.parse(text);
|
pageJson = JSON.parse(text);
|
||||||
} catch {
|
} catch {
|
||||||
// 以字元(而非 UTF-16 碼元)截斷回傳內容片段,避免拆分多位元組字元造成亂碼
|
// 以字元(而非 UTF-16 碼元)截斷回傳內容片段,避免拆分多位元組字元造成亂碼
|
||||||
const contentSnippet = Array.from(text).slice(0, 200).join('');
|
const contentSnippet = Array.from(text).slice(0, API_ERROR_SNIPPET_LENGTH).join('');
|
||||||
throw new Error(`release API 回傳資料無法解析 (page=${page}),回應內容片段:「${contentSnippet}」`);
|
throw new Error(`release API 回傳資料無法解析 (page=${page}),回應內容片段:「${contentSnippet}」`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user
嚴重等級:🔵 建議
審查員:Leo
問題:在
assertGiteaRepositoryFormat函式中,當value.split('/')的長度不為 2 時,拋出的錯誤訊息僅籠統地說「格式錯誤」。若使用者輸入了包含多個斜線或完全沒有斜線的字串,這類訊息對修正環境變數幫助有限。建議:建議區分「格式不符」與「內容不符」的錯誤細節,例如提示「必須為 owner/repo 格式,包含一個斜線」。