Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions checks/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
27 changes: 27 additions & 0 deletions checks/cli_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package checks

import (
"encoding/json"
"runtime"
"testing"

Expand Down Expand Up @@ -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, "• Żółć")
}
}
Loading