fix(shell): preserve UTF-8 native input on PowerShell 5 (#5160)

Windows PowerShell 5.1 defaults $OutputEncoding to US-ASCII, corrupting non-ASCII strings piped to native commands. Set it from the console encoding only on legacy versions so PowerShell 7 keeps its defaults.
This commit is contained in:
Zhou
2026-07-29 21:47:01 +08:00
committed by GitHub
parent 757ad9c764
commit 5a28a6165c
2 changed files with 21 additions and 3 deletions
+1
View File
@@ -556,6 +556,7 @@ class ExecTool(Tool):
command = ExecTool._normalize_powershell_command(command)
command = (
"[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)\n"
"if ($PSVersionTable.PSVersion.Major -lt 6) { $OutputEncoding = [Console]::OutputEncoding }\n"
"$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'\n"
f"{command}\n"
"if ($LASTEXITCODE -ne $null) { exit $LASTEXITCODE }"