Fix WebResponseObject ToString encoding#27178
Open
badgerbees wants to merge 1 commit intoPowerShell:masterfrom
Open
Fix WebResponseObject ToString encoding#27178badgerbees wants to merge 1 commit intoPowerShell:masterfrom
badgerbees wants to merge 1 commit intoPowerShell:masterfrom
Conversation
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes WebResponseObject.ToString() so response bodies preserve non-ASCII characters by decoding using the response charset (falling back to the WebCmdlet default encoding), while keeping the legacy ASCII-based RawContent preview behavior unchanged.
Changes:
- Update
WebResponseObject.ToString()to decodeContentusing the responseContent-Typecharset viaStreamHelper.TryGetEncoding(...)instead of ASCII. - Preserve the existing ASCII
RawContentpreview output by moving the old preview logic into a dedicated helper. - Add a regression assertion ensuring
.ToString()preserves UTF-8 response content inInvoke-WebRequesttests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebResponseObject.Common.cs |
Decodes .ToString() using the response charset while preserving the ASCII RawContent preview behavior via a new helper. |
test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 |
Adds a regression check that .ToString() contains expected UTF-8 characters. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
Fix
WebResponseObject.ToString()so non-ASCII response content is preserved by decoding with the response charset instead of ASCII. Keep the legacyRawContentpreview behavior unchanged and add a regression test for a UTF-8 response body, also this fixes issue #27154.PR Context
Invoke-WebRequestresponses were losing non-ASCII characters when callers relied on.ToString(). This change keeps the fix narrow by updating the stringification path only, leaving the existingRawContentpreview logic alone and covering the reported UTF-8 case with a regression test.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header