Visitar URL original
Invoke-WebRequest's .ToString() assumes content is ASCII · Issue #27154 · PowerShell/PowerShell · GitHub
Skip to content

Invoke-WebRequest's .ToString() assumes content is ASCII #27154

Description

Prerequisites

Steps to reproduce

When you call .ToString() on a response from Invoke-WebRequest the code here assumes ascii in the content body

https://github.com/PowerShell/PowerShell/blob/45a80d9a4894802a61637cc7c8843bc66b0bcc5d/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebResponseObject.Common.cs#L187C13-L187C69

If the content is non-ascii this causes characters to be converted to '???'

Expected behavior

Non-ascii characters in the response body remain unchanged

Actual behavior

Non-ascii characters become '???'

Error details

Environment data

Name                           Value
----                           -----
PSVersion                      7.6.0
PSEdition                      Core
GitCommitId                    7.6.0
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Activity

  1. TobiasPSP commented on May 6, 2026

    @TobiasPSP
    Collaborator

    toString() is a fuzzy "preview" function, not the recommended way to process production data. The challenge is: with text and non-BOM-encoding, there is no way other than heuristically to determine the original encoding.

    So toString() must pick one encoding in random best effort. Or is there a reliable HTTP header information that reveals the encoding? I am not much of a HTTP expert I admit.

  2. moved this from Queue to In-Progress-Issues in Cmdlets Working Groupon Jul 15, 2026
  3. SteveL-MSFT commented on Jul 15, 2026

    @SteveL-MSFT
    Member

    @PowerShell/wg-powershell-cmdlets discussed this. We believe in most cases the encoding should be available as part of the header. If not, it would make sense to default to utf-8 instead of ASCII.

  4. added
    Issue-BugIssue has been identified as a bug in the product
    Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributors
    WG-ReviewedA Working Group has reviewed this and made a recommendation
    and removed
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    WG-NeedsReviewNeeds a review by the labeled Working Group
    on Jul 15, 2026
  5. moved this from In-Progress-Issues to Reviewed in Cmdlets Working Groupon Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions