Skip to content

Commit 1de7851

Browse files
committed
fix: use .NET Regex.Replace for count-limited replacement in PowerShell
Addresses Copilot feedback: PowerShell's -replace operator does not support a third argument for replacement count. Using it causes an error or mis-parsing that would break forge package generation on Windows. Changed from: $content -replace '(?m)^---$', "---`nname: $cmdName", 1 To: $regex = [regex]'(?m)^---$' $content = $regex.Replace($content, "---`nname: $cmdName", 1) The .NET Regex.Replace() method properly supports the count parameter, ensuring the name field is injected only after the first frontmatter delimiter (not the closing one). This fix is critical for Windows users running: specify init --ai forge --offline
1 parent 506b7ef commit 1de7851

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

.github/workflows/scripts/create-release-packages.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,9 @@ function Build-Variant {
498498
$cmdName = [System.IO.Path]::GetFileNameWithoutExtension($cmdFile.Name)
499499
$content = Get-Content -Path $cmdFile.FullName -Raw
500500

501-
# Inject name field after first ---
502-
$content = $content -replace '(?m)^---$', "---`nname: $cmdName", 1
501+
# Inject name field after first --- using .NET Regex.Replace with count limit
502+
$regex = [regex]'(?m)^---$'
503+
$content = $regex.Replace($content, "---`nname: $cmdName", 1)
503504

504505
Set-Content -Path $cmdFile.FullName -Value $content -NoNewline
505506
}

0 commit comments

Comments
 (0)