Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -1609,9 +1609,43 @@

if (ContentHelper.IsTextBasedContentType(ContentHelper.GetContentType(response)))
{
debugBuilder.AppendLine(
response.Content.ReadAsStringAsync(_cancelToken.Token)
.GetAwaiter().GetResult());
string body;

try
{
// Normal path
body = response.Content
.ReadAsStringAsync(_cancelToken.Token)
.GetAwaiter().GetResult();
}
catch (InvalidOperationException)
{
// Fallback for invalid charset (e.g., "utf8")
var headers = response.Content.Headers;
string charset = headers?.ContentType?.CharSet;

Check failure on line 1625 in src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs

View workflow job for this annotation

GitHub Actions / Build PowerShell

Converting null literal or possible null value to non-nullable type.

Check failure on line 1625 in src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs

View workflow job for this annotation

GitHub Actions / xUnit Tests / Run xUnit Tests

Converting null literal or possible null value to non-nullable type.

Check failure on line 1625 in src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs

View workflow job for this annotation

GitHub Actions / Build PowerShell

Converting null literal or possible null value to non-nullable type.

Check failure on line 1625 in src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs

View workflow job for this annotation

GitHub Actions / xUnit Tests / Run xUnit Tests

Converting null literal or possible null value to non-nullable type.

Check failure on line 1625 in src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs

View workflow job for this annotation

GitHub Actions / CodeQL Analysis / Analyze (csharp)

Converting null literal or possible null value to non-nullable type.

Check failure on line 1625 in src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs

View workflow job for this annotation

GitHub Actions / Build PowerShell

Converting null literal or possible null value to non-nullable type.

Check failure on line 1625 in src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs

View workflow job for this annotation

GitHub Actions / xUnit Tests / Run xUnit Tests

Converting null literal or possible null value to non-nullable type.

Encoding encoding;

try
{
encoding = !string.IsNullOrEmpty(charset)
? Encoding.GetEncoding(charset)
: Encoding.UTF8;
}
catch (ArgumentException)
{
// Final fallback
encoding = Encoding.UTF8;
}

var bytes = response.Content
.ReadAsByteArrayAsync(_cancelToken.Token)
.GetAwaiter().GetResult();

body = encoding.GetString(bytes);
}

debugBuilder.AppendLine(body);
}
else
{
Expand Down
Loading