fix(release-cleanup): 以 pathToFileURL 判斷直接執行入口
改用 node:url 的 pathToFileURL(process.argv[1]).href 比對,正確處理含空白/ 特殊字元路徑與跨平台差異,取代脆弱的手動 file:// 字串拼接。 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
cafb33d725
commit
f1fce4b6e4
+3
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user