Repository navigation
Fix PowerShell pipeline encoding for localized package names (issue #4507) #6704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8f61400
a816f06
44a1f1d
d043a21
14d0228
0bdc562
5a37a8a
ec1eecd
302c73f
62ed9d9
82c9d66
42e7bbb
34137d7
71ab9b3
80bc1c2
05296ee
4adc774
a49387e
02af947
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| ## Bug Fixes | ||
|
|
||
| ### Redirected human-readable output uses the console code page | ||
|
|
||
| Human-readable output that is redirected to a pipe is now written in the console's output code | ||
| page instead of UTF-8. A console host decodes the output of a native command with the code page | ||
| that was active before the command started, so `winget list --source winget | Sort-Object Name` | ||
| in PowerShell on a Russian or Ukrainian system now displays localized package names instead of | ||
| garbled text (https://github.com/microsoft/winget-cli/issues/4507). | ||
|
|
||
| The conversion only applies while standard output is a pipe and the code page is not already | ||
| UTF-8. Output that the operating system redirects to a file is not converted, and | ||
| machine-readable channels (such as the JSON output of the DSC commands) and completion output | ||
| always stay UTF-8. | ||
|
|
||
| Characters that the console code page cannot represent are written as `?`, and characters that | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this reason, I'm not sure we can make
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JohnMcPMS In my opinion it's better than what I get without this pr:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens with this change when you apply the well-known mitigation of setting the encodings in |
||
| the code page has a closest equivalent for use that equivalent. On a system whose console uses | ||
| code page 866, for example, the `โฆ` table truncation marker is written as `:`, and Japanese or | ||
| Ukrainian `ั`/`า` characters are written as `?`. For lossless output in PowerShell, set | ||
| `[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()` to update both the console | ||
| code page and PowerShell's cached decoder. Use a UTF-8-capable terminal such as | ||
| [Windows Terminal](https://github.com/microsoft/terminal). For tools that already expect UTF-8, | ||
| set the new [`output.encoding`](https://github.com/microsoft/winget-cli/blob/master/doc/Settings.md#encoding) | ||
| setting to `utf8`, or pass `--output-encoding utf8` to a single command. | ||
|
|
||
| Profiles that already apply the mitigation in `$PROFILE` keep working: they set the console code | ||
| page to UTF-8 before WinGet starts, so WinGet sees a UTF-8 code page and writes UTF-8 without | ||
| converting anything. | ||
|
|
||
| This works around the console host decoding behavior. The underlying PowerShell issues are | ||
| https://github.com/PowerShell/PowerShell/issues/28496 and | ||
| https://github.com/PowerShell/PowerShell/issues/28498. | ||

Uh oh!
There was an error while loading. Please reload this page.