Fix to fallback to utf-8 when provided an invalid charset in web responses - #27789
Fix to fallback to utf-8 when provided an invalid charset in web responses#27789Ryan Yates (kilasuit) wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
24c6416 to
32213ad
Compare
32213ad to
238f78e
Compare
|
I don't think this is a good solution. It is not appropriate to assume anything you don't understand is UTF-8 without giving any indication of a problem. If somebody specifies a charset it is done for a reason. If you ignore it and carry on then you are risking corrupting the data. PowerShell already has a mapping for 'utf8' and it is used by Get-Content and Set-Content. Rather than invent a new standard here, I suggest this component should be consistent with the rest of PowerShell. Instead of tying to get the system encoding, catching an exception and then pretending everything is UTF-8, it should be the same algorithm as Get-Content. There is a dictionary of string to encoding already maintained by PowerShell as System.Management.Automation.EncodingConversion.encodingMap. This dictionary should be consulted first with a TryGetValue, if that fails it should then use the system provider with Encoding.GetEncoding(). Then if that throws an exception, then so be it. That would address the 'utf8' issue in a PowerShell consistent manner and not break by misinterpreting unknown character set encodings. |
PR Summary
This adds in the conversion when servers respond with
charset=utf8& other non recognised charsets.By doing so the Debug message that contains the WebResponse Body is returned as expected by developers or end users of the WebCmdlets
PR Context
fixes #27788
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header