-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Resolution-FixedThe issue is fixed.The issue is fixed.
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Invoke-WebRequest POST with -Body (string) and -Headers containing a content type with charset (ex. plain/text; charset="windows-1251") and no -ContentType.
Invoke-WebRequest -URI "some uri" -Method POST -Headers @{Content-Type="plain/text; charset=windows-1251"} -Body "string encoded with windows-1251 charset"The charset in the headers are ignored be ignored and default to UTF8.
This doesn't happen if we use -ContentType
Invoke-WebRequest -URI "some uri" -Method POST -ContentType "plain/text; charset=windows-1251" -Body "string encoded with windows-1251 charset"Both should have the same behaviour
I found this possible bug while reading the code; I haven't encountered it in the real world so I don't really know how we could test it (and if testing it is even possible)
Expected behavior
SetRequestContent should try to get the charset from the ContentType in Headers saved in the WebSession
WebSession.ContentHeaders[HttpKnownHeaderNames.ContentType]Actual behavior
SetRequestContent only checks for -ContentType charsetError details
While writing some code in `WebRequestPSCmdlet.Common.cs` think I found a BUG (line 1491) it should check for `WebSession.ContentHeaders[HttpKnownHeaderNames.ContentType]` instead of `ContentType` (this should be ok because if both are present `ContentType` overwrites `WebSession.ContentHeaders[HttpKnownHeaderNames.ContentType]`) unfortunately I don't know how to test it (I think it would require sending a wierdily encoded string as Body), if confirmed I'll open another PR to fix it.Environment data
Latest master
https://github.com/PowerShell/PowerShell/blob/60b4e9704fca546f76e1128e30de4077c51a3ca2/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.csVisuals
No response
Metadata
Metadata
Assignees
Labels
Resolution-FixedThe issue is fixed.The issue is fixed.