Closed sobanieca closed 5 years ago
Regarding point 3 - I've just created AspNetCore 2.1.* project from template in VS and when running request with "application/json" content and some dummy xml inside I'm getting BadRequest out-of-the-box (as expected). So I wonder, why it's not working for MvcSandbox application... Is it because of lack of .UseMvc() instruction in startup.cs?
Thanks for your effort, @sobanieca. As part of the repo reduction effort (https://github.com/aspnet/Announcements/issues/330) we're closing all the PRs in this repo. Please reopen this PR against the AspNetCore repo so we can consider it.
This PR is an attempt to fix an issue 3959 (link) reported in AspNetCore repository. However, I need some help :)
I was able to reproduce issue in unit tests (BodyModelBinderTests) with exactly the same exception being thrown as in reported issue. However, I wasn't able to programmatically generate some ANSI encoding string so I had to introduce embedded text file in unit tests project. Such file can be saved in UTF-8 at any time and whole test won't be able to catch encoding issue (or will generate build errors). To generate ANSI string (for example Windows-1250 encoded) I wanted to use System.Text.Encoding.CodePages NuGet package. How can I install it? From what I can see NuGet feed is not available (which kinda makes sense to me)? Maybe I'm missing something?
DecoderFallbackException - I've assumed that such non-unicode characters in unicode expected value always result in DecoderFallbackException as this is the exception that is being thrown. From my research it looks like this exception is always thrown when there are issues with encoding, so it should always result in some 400 Bad Request response to the client.
After implementing 'fix' and running unit tests, I've modified samples/MvcSandbox application so it contains following method in LoginController:
And used similar powershell as the one from issue repro steps (https://github.com/sobanieca/AspNetCoreEncodingIssue)
However, in response it gives me 204 status code. I would expect to see 400 - Bad Request here (with the code from PR). I did some more digging and changed Powershell so I'm sending XML instead of JSON:
I would expect to see 400 - Bad Request here as well. But instead, I've seen 204 again. Is there any issue with 3.* MVC, or I'm just missing something?