fix(v3.2.0): profile 注入 null 崩溃 (全新机器 profile.ps1 不存在)

Get-Content -Raw 对空文件返回 $null 而非空字符串,
导致 [regex]::Replace($null, ...) 抛 ArgumentNull。
加 null-coalesce 兜底为空字符串。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
bookworm 2026-04-27 23:15:01 +08:00
parent 5ca772ebbe
commit fa287ae27d
2 changed files with 2 additions and 1 deletions

Binary file not shown.

View File

@ -810,7 +810,8 @@ $sentinelEnd
try {
if (-not (Test-Path $t.Dir)) { New-Item -ItemType Directory -Path $t.Dir -Force -EA Stop | Out-Null }
$psProfilePath = Join-Path $t.Dir $t.File
$existing = if (Test-Path $psProfilePath) { Get-Content $psProfilePath -Raw -Encoding UTF8 } else { "" }
$existing = if (Test-Path $psProfilePath) { (Get-Content $psProfilePath -Raw -Encoding UTF8 -EA SilentlyContinue) } else { $null }
if (-not $existing) { $existing = "" }
# 同时清理 v3.0.11 旧 sentinel (BW_CRED_START v3.0.11 ...)
$oldPattern = "# BW_CRED_START v3\.0\.\d+[\s\S]*?# BW_CRED_END"
$existing = [regex]::Replace($existing, $oldPattern, "")