Repository navigation
Terminal dot segments lose URL path trailing slash and change relative redirects #3802
Replies: 2 comments
|
Normalize first to preserve the trailing slash. Verified with HTTPX 0.28.1 from urllib.parse import urljoin
import httpx
url = httpx.URL(urljoin("https://example.com/", "/x/y/.."))
print(url.join("child")) |
|
I checked your proposed trailing-slash correction on The distinction is supported by RFC 3986 §5.2.4, steps B/C: a terminal if path.startswith("/") and path.endswith(("/.", "/..")):
output.append("")I added 58 local cases: 34 fail on the original checkout, and all 58 pass with this correction. Besides your examples, these cover normalization to the root, walking above the root, repeated slashes, keyword construction and I also checked actual redirect handling through The full suite with just this local correction has 1,473 passed, 1 skipped, 2 failed. Both failures also occur on the unmodified base: |
Uh oh!
There was an error while loading. Please reload this page.
Potential issue
httpx.URLdrops the trailing slash when the input path ends in/.or/... This changes the request target and where relative redirects resolve, even though RFC 3986 §5.2.4 preserves a trailing/after removing a terminal dot segment.Minimal reproduction
Actual:
Expected after normalizing
/x/y/..to/x/:This also reproduces for
/x/.and/x/y/.. An in-processMockTransportredirect from/x/y/..withLocation: childrequests/xthen/child, instead of/x/then/x/child.Investigation
httpx/_urlparse.py:447-475,normalize_path(), removes terminal.and..components without retaining the directory-ending slash. One possible localized fix is to append an empty component when an absolute path ends in/.or/..; regression tests can cover URL construction,.raw_path,.join()and redirects. Is this consistent with HTTPX's intended URL normalization behavior? If maintainers agree, I can submit a focused PR.Verified against default-branch commit
b5addb64f0161ff6bfe94c124ef76f6a1fba5254, HTTPX 0.28.1, Python 3.12.13 on Windows; checked open/closed issues and PRs for terminal dot segments and trailing slashes without finding this case.AI disclosure: bug discovery assisted by Luna (
timotty-responses/luna); reproduction and proposed fix reviewed with OpenCode (GPT-6 Sol). No PR has been published.All reactions