-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add the feature flag that allows users to opt out automatic UTF8 console encoding #51261
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: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -25,19 +25,22 @@ public static void Setup() | |
| FlowOverrideToChildProcesses(language); | ||
| } | ||
|
|
||
| if ( | ||
| !CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.Equals("en", StringComparison.InvariantCultureIgnoreCase) && | ||
| if (Environment.GetEnvironmentVariable("CONSOLE_USE_DEFAULT_ENCODING") != "1") | ||
|
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. Similar to my comment on the MSBuild side - this feels wrong. If we know the locale that we're using, and we know that the locale doesn't support UTF8 output for some reason, then we shouldn't do the UTF8 encoding change. |
||
| { | ||
| if ( | ||
| !CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.Equals("en", StringComparison.InvariantCultureIgnoreCase) && | ||
| #if NET | ||
| OperatingSystemSupportsUtf8() | ||
| OperatingSystemSupportsUtf8() | ||
| #else | ||
| CurrentPlatformIsWindowsAndOfficiallySupportsUTF8Encoding() | ||
| CurrentPlatformIsWindowsAndOfficiallySupportsUTF8Encoding() | ||
| #endif | ||
| ) | ||
| { | ||
| // Setting both encodings causes a change in the CHCP, making it so we don't need to P-Invoke ourselves. | ||
| Console.OutputEncoding = s_defaultMultilingualEncoding; | ||
| Console.InputEncoding = s_defaultMultilingualEncoding; | ||
| // If the InputEncoding is not set, the encoding will work in CMD but not in Powershell, as the raw CHCP page won't be changed. | ||
| ) | ||
| { | ||
| // Setting both encodings causes a change in the CHCP, making it so we don't need to P-Invoke ourselves. | ||
| Console.OutputEncoding = s_defaultMultilingualEncoding; | ||
| Console.InputEncoding = s_defaultMultilingualEncoding; | ||
| // If the InputEncoding is not set, the encoding will work in CMD but not in Powershell, as the raw CHCP page won't be changed. | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,10 +31,13 @@ public static int Main(string[] args) | |
| { | ||
| using AutomaticEncodingRestorer _ = new(); | ||
|
|
||
| // Setting output encoding is not available on those platforms | ||
| if (UILanguageOverride.OperatingSystemSupportsUtf8()) | ||
| if (Environment.GetEnvironmentVariable("CONSOLE_USE_DEFAULT_ENCODING") != "1") | ||
|
||
| { | ||
| Console.OutputEncoding = Encoding.UTF8; | ||
| // Setting output encoding is not available on those platforms | ||
| if (UILanguageOverride.OperatingSystemSupportsUtf8()) | ||
| { | ||
| Console.OutputEncoding = Encoding.UTF8; | ||
| } | ||
| } | ||
|
|
||
| DebugHelper.HandleDebugSwitch(ref args); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting the environment variable name and value into named constants to avoid magic strings and improve maintainability. This duplicates the same magic strings used in Program.cs.