Repository navigation
Terminal dot segments lose URL path trailing slash and change relative redirects #3802
Unanswered
Timotty
asked this question in
Potential Issue
Replies: 1 comment
|
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")) |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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