From eba176f125984469d48869967f151705546aebc5 Mon Sep 17 00:00:00 2001 From: Theo Beers Date: Thu, 24 Sep 2026 11:59:50 -0400 Subject: [PATCH] ensure powershell commands return utf-8 output --- checks/cli.go | 3 +++ checks/cli_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/checks/cli.go b/checks/cli.go index 8d86e8f..26345b8 100644 --- a/checks/cli.go +++ b/checks/cli.go @@ -94,6 +94,9 @@ func runCLICommandWithOutputLimit( result.FinalCommand = finalCommand result.Command = command + if shell.commandFlag == "-Command" { + finalCommand = "[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false); " + finalCommand + } cmd := exec.Command(shell.path, shell.commandFlag, finalCommand) cmd.Env = append(os.Environ(), "LANG=en_US.UTF-8") diff --git a/checks/cli_test.go b/checks/cli_test.go index afd28d5..d243383 100644 --- a/checks/cli_test.go +++ b/checks/cli_test.go @@ -1,6 +1,7 @@ package checks import ( + "encoding/json" "runtime" "testing" @@ -167,3 +168,29 @@ func TestParseStdoutVariablesRejectsInvalidConfiguration(t *testing.T) { }) } } + +func TestRunCLICommandPowerShellUTF8(t *testing.T) { + shell := defaultShell() + if runtime.GOOS != "windows" { + var err error + shell, err = resolveShell("pwsh") + if err != nil { + t.Skipf("PowerShell is unavailable: %v", err) + } + } + + result := runCLICommand(api.CLIStepCLICommand{ + Command: `'• Żółć' | ConvertTo-Json -Compress`, + }, map[string]string{}, shell) + if result.Err != "" || result.ExitCode != 0 { + t.Fatalf("error = %q, exit code = %d, stderr = %q", result.Err, result.ExitCode, result.Stderr) + } + + var got string + if err := json.Unmarshal([]byte(result.Stdout), &got); err != nil { + t.Fatalf("invalid JSON output %q: %v", result.Stdout, err) + } + if got != "• Żółć" { + t.Fatalf("decoded output = %q, want %q", got, "• Żółć") + } +}