diff --git a/upath/implementations/http.py b/upath/implementations/http.py index 12320a9b..94fb8207 100644 --- a/upath/implementations/http.py +++ b/upath/implementations/http.py @@ -106,8 +106,9 @@ def resolve( parts = list(self.parts) if parts[-1:] == ["."]: parts[-1:] = [""] - if parts[-2:] == ["", ".."]: - parts[-2:] = [""] + if parts[-1:] == [".."]: + # a final ".." names a directory: "/a/b/.." -> "/a/" + parts.append("") pth = self.with_segments(*parts) resolved_path = super(HTTPPath, pth).resolve(strict=strict) diff --git a/upath/tests/implementations/test_http.py b/upath/tests/implementations/test_http.py index a5525ba8..2f34ba27 100644 --- a/upath/tests/implementations/test_http.py +++ b/upath/tests/implementations/test_http.py @@ -184,6 +184,8 @@ def test_joinuri_behavior(base, rel, expected): ("http://example.com/a/..//.", "http://example.com//"), ("http://example.com/a/..//..", "http://example.com/"), ("http://example.com/a/../b", "http://example.com/b"), + ("http://example.com/a/b/..", "http://example.com/a/"), + ("http://example.com/a/b/../c/..", "http://example.com/a/"), ("http://example.com/a/..//b", "http://example.com//b"), ("http://example.com/a//..", "http://example.com/a/"), ("http://example.com/a//../", "http://example.com/a/"), diff --git a/upath/tests/test_special_paths.py b/upath/tests/test_special_paths.py index 01b5d8b4..7baa1f9e 100644 --- a/upath/tests/test_special_paths.py +++ b/upath/tests/test_special_paths.py @@ -79,9 +79,6 @@ " on root_marker='' filesystems (github, webdav, hf, tar)" ), "hdfs-trailing-slash": "candidate bug: hdfs keeps trailing slashes", - "http-final-dotdot": ( - "candidate bug: a final '..' drops the trailing slash on http(s) paths" - ), } @@ -418,7 +415,6 @@ def test_empty_parts_are_supported(protocol): assert p.parts == (root.anchor, "a", "", "b") -@_xfail("http-final-dotdot") def test_http_resolve_final_dotdot_is_a_directory(): # RFC 3986, section 5.2.4: "/a/b/.." normalizes to "/a/" p = UPath("https://example.com/a/b/..")