fix(powershell): ensure UTF-8 templates are written without BOM#2280
fix(powershell): ensure UTF-8 templates are written without BOM#2280Nimraakram22 wants to merge 3 commits intogithub:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the PowerShell feature/setup scripts to ensure generated markdown files are written as UTF-8 without BOM (avoiding BOM-related parsing issues in Unix-style tooling).
Changes:
- Replaced
Copy-Itemtemplate copying with a read +[System.IO.File]::WriteAllText(...)flow to force UTF-8 no BOM output. - Applied the same UTF-8 no BOM write approach in both
setup-plan.ps1andcreate-new-feature.ps1.
Show a summary per file
| File | Description |
|---|---|
| scripts/powershell/setup-plan.ps1 | Writes plan.md from the template using UTF-8 no BOM instead of Copy-Item. |
| scripts/powershell/create-new-feature.ps1 | Writes spec.md from the template using UTF-8 no BOM instead of Copy-Item. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (2)
scripts/powershell/setup-plan.ps1:39
- Variable
$Utf8NoBomis PascalCase while other local variables in this file are lower camelCase (e.g.,$paths,$template,$content). Consider renaming to match the local variable naming convention (e.g.,$utf8NoBom).
$Utf8NoBom = New-Object System.Text.UTF8Encoding($false)
scripts/powershell/create-new-feature.ps1:355
- Local variables in this script use lower camelCase (e.g.,
$featureDesc,$branchName), but$Utf8NoBomis PascalCase. Consider renaming to match the file's convention (e.g.,$utf8NoBom).
$Utf8NoBom = New-Object System.Text.UTF8Encoding($false)
- Files reviewed: 2/2 changed files
- Comments generated: 3
mnriem
left a comment
There was a problem hiding this comment.
Please address Copilot feedback. If not appicable, please explain why
|
@mnriem Done! I have updated both setup-plan.ps1 and create-new-feature.ps1 to: Use -Encoding UTF8 when reading templates to ensure character integrity. Use lower camelCase for the $utf8NoBom variable. Fix the indentation of the .NET write method calls. |
There was a problem hiding this comment.
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (2)
scripts/powershell/create-new-feature.ps1:355
- The PR description says the write is hardened "regardless of the source template's encoding", but
Get-Content -Encoding UTF8forces UTF-8 decoding. If a resolved template is UTF-16/UTF-32 (common for Windows-authored files) this will corrupt content. Consider reading via a BOM-detecting API (e.g.,[System.IO.File]::ReadAllText($template)/StreamReaderwith BOM detection) and then writing withUTF8Encoding($false).
$content = Get-Content -Raw -Encoding UTF8 -Path $template
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
scripts/powershell/setup-plan.ps1:41
Get-Content -Encoding UTF8forces UTF-8 decoding, so this doesn't fully meet the stated goal of being robust to template encoding (e.g., UTF-16 templates with a BOM would be mis-decoded). Prefer a BOM-detecting read (such as[System.IO.File]::ReadAllText($template)) before writing out withUTF8Encoding($false).
$content = Get-Content -Raw -Encoding UTF8 -Path $template
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($paths.IMPL_PLAN, $content, $utf8NoBom)
- Files reviewed: 2/2 changed files
- Comments generated: 2
|
Please address Copilot feedback. If not applicable please explain why |
|
@mnriem "Fixed! I have updated the scripts based on Copilot's feedback: Switched to [System.IO.File]::ReadAllText() for more robust template encoding detection. Corrected the variable name from $targetPath to $specFile in create-new-feature.ps1. Cleaned up the duplicate comments and indentation. Ready for another look!" |
There was a problem hiding this comment.
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
Description
This PR fixes an issue where PowerShell 5.1 (default on Windows) writes files like CLAUDE.md with a UTF-8 Byte Order Mark (BOM). This invisible prefix causes parsing errors in modern tools like Claude Code and other Unix-style CLI utilities.
Changes
Stripped BOM from existing templates: Found and removed the BOM from all .md files in the templates/ and presets/ directories.
Hardened PowerShell logic: Replaced Copy-Item with a .NET based write method ([System.IO.File]::WriteAllText) in setup-plan.ps1 and create-new-feature.ps1 to force "UTF-8 No BOM" output, regardless of the source template's encoding.
Verification
Verified using the file command in MINGW64 to ensure output files now show as UTF-8 Unicode text instead of UTF-8 Unicode (with BOM) text.