Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions httpx/_urlparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ def normalize_path(path: str) -> str:
output.pop()
else:
output.append(component)
# RFC 3986 preserves a directory-ending slash for terminal dot segments.
if path.endswith(("/.", "/..")):
output.append("")
return "/".join(output)


Expand Down
21 changes: 21 additions & 0 deletions tests/models/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,3 +861,24 @@ def test_ipv6_url_copy_with_host(url_str, new_host):
assert url.host == "::ffff:192.168.0.1"
assert url.netloc == b"[::ffff:192.168.0.1]:1234"
assert str(url) == "http://[::ffff:192.168.0.1]:1234"


@pytest.mark.parametrize(
("path", "expected"),
[
("/x/.", "/x/"),
("/x/y/..", "/x/"),
("/x/y/.", "/x/y/"),
("/.", "/"),
("/..", "/"),
("/x/y/../..", "/"),
("/x/y/../", "/x/"),
("/x/.file", "/x/.file"),
],
)
def test_terminal_dot_segments_preserve_directory_slash(path, expected):
url = httpx.URL("https://example.com" + path)
assert url.path == expected
assert url.raw_path == expected.encode()
if path.endswith(("/.", "/..")):
assert str(url.join("child")) == "https://example.com" + expected + "child"
Loading