New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wsgiref.simple_server: mojibake with cp1252 bytes in PATH_INFO #70904
Comments
Patch attached with test. In summary: A request to the url b'/\x80' appears to the application as a request to b'\xc2\x80' -- The issue being the latin1 decoded PATH_INFO is re-encoded as UTF-8 and then decoded as latin1 (on the wire) b'\x80' -(decode latin1)-> u'\x80' -(encode utf-8)-> b'\xc2\x80' -(decode latin1)-> b'\xc2\x80' My patch cuts out the encode(utf-8)->decode(latin1) |
A few typos in my previous comment, pressed enter too quickly, here's an updated comment: Patch attached with test. In summary: A request to the url b'/\x80' appears to the application as a request to b'/\xc2\x80' -- The issue being the latin1 decoded PATH_INFO is re-encoded as UTF-8 and then decoded as latin1
My patch cuts out the encode(utf-8)->decode(latin1):
|
Oops, broke b'/%80'. Here's a better fix that now takes:
to:
|
I was going to say your original fix was the reverse of a change in r86146. But you seem to be fixing the problems before I express them :) For the fix I would suggest something like unquote(path, "latin-1") would be simpler. I left some other review comments about the tests. |
Updates after review. |
Thanks, this version looks pretty good to me. |
Forgot to remove the pyver code (leaning a bit too much on pre-commit) |
New changeset 1f2cfcd5a83f by Martin Panter in branch '3.5': New changeset 815a4ac67e68 by Martin Panter in branch 'default': |
Why wsgiref uses latin1? It must use utf-8. |
PEP-3333 states that environ variables are str variables decoded using Therefore, to get the original bytes, one must encode using latin1
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: