From 4048a20fc86c87e84c8cb70676090a1fc63f94b3 Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Fri, 2 Dec 2022 10:58:42 +0100 Subject: [PATCH] Encoding.RegisterProvider(CodePagesEncodingProvider.Instance) --- .../utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs | 4 ++++ .../commands/utility/WebCmdlet/StreamHelper.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs index 21be97d567e..1495c21707d 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs @@ -1682,6 +1682,8 @@ internal long SetRequestContent(HttpRequestMessage request, byte[] content) /// internal long SetRequestContent(HttpRequestMessage request, string content) { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + if (request == null) throw new ArgumentNullException(nameof(request)); @@ -1731,6 +1733,8 @@ internal long SetRequestContent(HttpRequestMessage request, string content) internal long SetRequestContent(HttpRequestMessage request, XmlNode xmlNode) { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + if (request == null) throw new ArgumentNullException(nameof(request)); diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs index 9314cfd1a5d..ceaf36a9a18 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs @@ -414,6 +414,8 @@ private static string StreamToString(Stream stream, Encoding encoding) internal static string DecodeStream(Stream stream, string characterSet, out Encoding encoding) { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + try { encoding = Encoding.GetEncoding(characterSet); @@ -428,6 +430,8 @@ internal static string DecodeStream(Stream stream, string characterSet, out Enco internal static bool TryGetEncoding(string characterSet, out Encoding encoding) { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + bool result = false; try {