Skip to content
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

Use UTF-8 encoding for UI helper standard output parsing #1326

Merged
merged 1 commit into from
Jul 11, 2023
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: 2 additions & 1 deletion src/shared/Core/Authentication/AuthenticationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ protected internal virtual async Task<IDictionary<string, string>> InvokeHelperA
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = false, // Do not redirect stderr as tracing might be enabled
UseShellExecute = false
UseShellExecute = false,
StandardOutputEncoding = EncodingEx.UTF8NoBom,
};

Context.Trace.WriteLine($"Starting helper process: {path} {args}");
Expand Down
8 changes: 8 additions & 0 deletions src/shared/Core/EncodingEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Text;

namespace GitCredentialManager;

public static class EncodingEx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a little trouble parsing the Ex piece of this name, although I'm sure there's a good reason why it was chosen.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.Encoding is a class that already exists. It's an old Windows convention to 'extend' a sealed/static class or function by giving it an 'Ex' suffix to signify some extra functionality.

Examples already in GCM: ConsoleEx, BoolConvertersEx and AssertEx.

{
public static readonly Encoding UTF8NoBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
}
8 changes: 3 additions & 5 deletions src/shared/Core/StandardStreams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public class StandardStreams : IStandardStreams
{
private const string LineFeed = "\n";

private static readonly Encoding Utf8NoBomEncoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);

private TextReader _stdIn;
private TextWriter _stdOut;
private TextWriter _stdErr;
Expand All @@ -41,7 +39,7 @@ public TextReader In
{
if (_stdIn == null)
{
_stdIn = new StreamReader(Console.OpenStandardInput(), Utf8NoBomEncoding);
_stdIn = new StreamReader(Console.OpenStandardInput(), EncodingEx.UTF8NoBom);
}

return _stdIn;
Expand All @@ -54,7 +52,7 @@ public TextWriter Out
{
if (_stdOut == null)
{
_stdOut = new StreamWriter(Console.OpenStandardOutput(), Utf8NoBomEncoding)
_stdOut = new StreamWriter(Console.OpenStandardOutput(), EncodingEx.UTF8NoBom)
{
AutoFlush = true,
NewLine = LineFeed,
Expand All @@ -71,7 +69,7 @@ public TextWriter Error
{
if (_stdErr == null)
{
_stdErr = new StreamWriter(Console.OpenStandardError(), Utf8NoBomEncoding)
_stdErr = new StreamWriter(Console.OpenStandardError(), EncodingEx.UTF8NoBom)
{
AutoFlush = true,
NewLine = LineFeed,
Expand Down