Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkl committed Oct 10, 2023
1 parent edfe819 commit 15c9aff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/NuGet.Core/NuGet.Build.Tasks.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ internal static bool TryParseArguments(string[] args, Func<Stream> getStream, Te
else
{
#endif
using var reader = new BinaryReader(getStream(), Encoding.UTF8, leaveOpen: true);
using var reader = new BinaryReader(getStream(), new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true), leaveOpen: true);

if (!TryDeserializeGlobalProperties(errorWriter, reader, out globalProperties))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public override bool Execute()

Dictionary<string, string> globalProperties = GetGlobalProperties();

Encoding utf8Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);

using (var semaphore = new SemaphoreSlim(initialCount: 0, maxCount: 1))
using (var loggingQueue = new TaskLoggingQueue(Log))
using (var process = new Process())
Expand All @@ -121,7 +123,7 @@ public override bool Execute()
RedirectStandardInput = true,
RedirectStandardOutput = true,
#if !NETFRAMEWORK
StandardInputEncoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false),
StandardInputEncoding = utf8Encoding,
#endif
UseShellExecute = false,
WorkingDirectory = Environment.CurrentDirectory,
Expand Down Expand Up @@ -150,7 +152,7 @@ public override bool Execute()
Encoding previousConsoleInputEncoding = Console.InputEncoding;

// Set the input encoding to UTF8 without a byte order mark, the spawned process will use this encoding on .NET Framework
Console.InputEncoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
Console.InputEncoding = utf8Encoding;

try
{
Expand All @@ -172,7 +174,7 @@ public override bool Execute()

if (SerializeGlobalProperties)
{
using var writer = new BinaryWriter(process.StandardInput.BaseStream, Encoding.UTF8, leaveOpen: true);
using var writer = new BinaryWriter(process.StandardInput.BaseStream, utf8Encoding, leaveOpen: true);

WriteGlobalProperties(writer, globalProperties);
}
Expand Down

0 comments on commit 15c9aff

Please sign in to comment.