Repository navigation
WSGITransport PATH_INFO changes UTF-8 bytes and breaks URL reconstruction #3798
Replies: 3 comments
|
Independently reproduced on Linux / Python 3.12.14 at master I checked eight paths, including literal and escaped UTF-8, One clarification to the previous reply: PATH_INFO should not retain the percent-encoded spelling. In this representation I also checked an adjacent boundary: with These are focused in-memory checks, not a full test-suite run or approval of your unpublished patch. |
|
Additional verification at master The review commit with extra tests credits @adenzhou1350's byte-preserving PATH_INFO proposal. It keeps the change limited to PATH_INFO. With this PATH_INFO change and the decoder candidate from #3799 applied together, the final full suite passed 1478 tests, 1 skipped on Linux/Python 3.12.14. The intermittent I can contribute these tests to the proposed fix. |
Uh oh!
There was an error while loading. Please reload this page.
Reproduced on current
master(b5addb64) with Python 3.12.13 on Windows and httpcore 1.0.9. No server or third-party WSGI framework is needed:Actual output:
Expected output:
WSGITransportcurrently setsPATH_INFOtorequest.url.path, which is decoded Unicode. PEP 3333 instead requires metadata strings to preserve bytes through Latin-1. That distinction changes the bytes oféand makes the standard-library URL reconstruction fail for中.This is related to #1365/#1391, but unquoting alone doesn't preserve that WSGI byte representation. Taking the raw path without its query, percent-decoding to bytes, then decoding with Latin-1 fixes these cases without changing HTTPX's public
URL.pathbehavior. It also preserves non-UTF-8 escaped bytes such as%FFrather than replacing them.I have a small local patch with 10 regression cases covering Unicode, escaped Unicode, non-UTF-8 bytes, encoded slashes, double escapes and query separation. The original fails 5 of those cases; the patch passes all 22 WSGI tests and all 136 tests in the combined WSGI/ASGI/URL suites. Ruff also passes. Would you be open to a PR for this?
All reactions