From f1fce4b6e4385fc4984f9530ade3045cbb8bb3f9 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 26 Jun 2026 14:14:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(release-cleanup):=20=E4=BB=A5=20pathToFileU?= =?UTF-8?q?RL=20=E5=88=A4=E6=96=B7=E7=9B=B4=E6=8E=A5=E5=9F=B7=E8=A1=8C?= =?UTF-8?q?=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 改用 node:url 的 pathToFileURL(process.argv[1]).href 比對,正確處理含空白/ 特殊字元路徑與跨平台差異,取代脆弱的手動 file:// 字串拼接。 Co-Authored-By: Claude Opus 4.8 (1M context) --- app/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/index.js b/app/index.js index 19044ed..3b809b6 100644 --- a/app/index.js +++ b/app/index.js @@ -1,5 +1,6 @@ // 進入點:載入設定、建立 Gitea 客戶端,依序清理舊成品與孤立 tag。 +import { pathToFileURL } from 'node:url' import { loadConfig } from './config.js' import { GiteaClient } from './gitea-client.js' import { cleanupReleases } from './releases.js' @@ -25,7 +26,8 @@ export async function main() { } // 僅在直接以 `node index.js` 執行時啟動主流程;被測試 import 時不自動執行,方便撰寫整合測試。 -if (import.meta.url === `file://${process.argv[1]}`) { +// 以 pathToFileURL 正確處理含空白/特殊字元的路徑與跨平台差異,避免手動拼接 file:// 的脆弱性。 +if (import.meta.url === pathToFileURL(process.argv[1]).href) { main().catch((error) => { failError(error) process.exit(1)