force Windows to always use preamble-free UTF8 input encoding (#22934)

* fixes #15770
* When running under the UTF-8 codepage, Powershell subprocesses will fail (eg, Start-Job, others) if the input encoding is using the default BOM preamble. This fix forces it to use no preamble in leaf_exec and win_shell, and includes tests to verify that Start-Job works.
This commit is contained in:
Matt Davis 2017-03-24 00:02:39 -07:00 committed by GitHub
commit e084e8809e
4 changed files with 26 additions and 0 deletions

View file

@ -90,6 +90,9 @@ $exec_args = $null
If(-not $executable -or $executable -eq "powershell") {
$exec_application = "powershell"
# force input encoding to preamble-free UTF8 so PS sub-processes (eg, Start-Job) don't blow up
$raw_command_line = "[Console]::InputEncoding = New-Object Text.UTF8Encoding `$false; " + $raw_command_line
# Base64 encode the command so we don't have to worry about the various levels of escaping
$encoded_command = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($raw_command_line))