Title: Investigate possible BUG Invoke-WebRequest content type charset · Issue #19156 · PowerShell/PowerShell · GitHub
Open Graph Title: Investigate possible BUG Invoke-WebRequest content type charset · Issue #19156 · PowerShell/PowerShell
X Title: Investigate possible BUG Invoke-WebRequest content type charset · Issue #19156 · PowerShell/PowerShell
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 reprodu...
Open Graph 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 PowerSh...
X 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 PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/19156
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Investigate possible BUG Invoke-WebRequest content type charset","articleBody":"### Prerequisites\r\n\r\n- [X] Write a descriptive title.\r\n- [X] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\r\n- [X] Search the existing issues.\r\n- [X] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\r\n- [X] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://docs.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\r\n\r\n### Steps to reproduce\r\n\r\nInvoke-WebRequest POST with -Body (string) and -Headers containing a content type with charset (ex. plain/text; charset=\"windows-1251\") and no -ContentType.\r\n\r\n```ps1\r\nInvoke-WebRequest -URI \"some uri\" -Method POST -Headers @{Content-Type=\"plain/text; charset=windows-1251\"} -Body \"string encoded with windows-1251 charset\"\r\n```\r\n\r\nThe charset in the headers are ignored be ignored and default to UTF8.\r\nThis doesn't happen if we use -ContentType\r\n\r\n```ps1\r\nInvoke-WebRequest -URI \"some uri\" -Method POST -ContentType \"plain/text; charset=windows-1251\" -Body \"string encoded with windows-1251 charset\"\r\n```\r\n\r\nBoth should have the same behaviour\r\n\r\nI 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)\r\n\r\n### Expected behavior\r\n\r\n```console\r\nSetRequestContent should try to get the charset from the ContentType in Headers saved in the WebSession\r\nWebSession.ContentHeaders[HttpKnownHeaderNames.ContentType]\r\n```\r\n\r\n\r\n### Actual behavior\r\n\r\n```console\r\nSetRequestContent only checks for -ContentType charset\r\n```\r\n\r\n\r\n### Error details\r\n\r\n```console\r\nWhile 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.\r\n```\r\n\r\n\r\n### Environment data\r\n\r\n```powershell\r\nLatest master\r\nhttps://github.com/PowerShell/PowerShell/blob/60b4e9704fca546f76e1128e30de4077c51a3ca2/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs\r\n```\r\n\r\n\r\n### Visuals\r\n\r\n_No response_","author":{"url":"https://github.com/CarloToso","@type":"Person","name":"CarloToso"},"datePublished":"2023-02-15T09:11:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":22},"url":"https://github.com/19156/PowerShell/issues/19156"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5fa52148-f285-ebac-3659-60c86a0a409c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E6CA:24F769:6BB3C4:98435F:6A57ADCE |
| html-safe-nonce | 0c8447c76c607fbb4d07ba659be99e9de6fc49af890131c483da828d19ee04ef |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNkNBOjI0Rjc2OTo2QkIzQzQ6OTg0MzVGOjZBNTdBRENFIiwidmlzaXRvcl9pZCI6IjQwODg3ODAzNzA0NjgxMjIwNjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 42c75ea98f336b3ee350763b4f5f50a3021571941b7bfee9c6d1232ee09d0848 |
| hovercard-subject-tag | issue:1585487979 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/19156/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e756a8cda0989beecd3be9a84de3757a8be6c39d569eca134835c2b0e9b381da/PowerShell/PowerShell/issues/19156 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e756a8cda0989beecd3be9a84de3757a8be6c39d569eca134835c2b0e9b381da/PowerShell/PowerShell/issues/19156 |
| og:image:alt | 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 PowerSh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | CarloToso |
| hostname | github.com |
| expected-hostname | github.com |
| None | 017a07c29bdd8a37b5907fc9a689338deb7103b5af7f56714193b2700229b3df |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4cd16a676f89d1cedb932671a5c2d20b8e60f86a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width