Skip to content

Commit f4adcf2

Browse files
committed
Handle absolute paths in zips.join_path
1 parent 421c4a5 commit f4adcf2

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

mammoth/zips.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,13 @@ def split_path(path):
6565

6666

6767
def join_path(*args):
68-
return "/".join(list(filter(None, args)))
68+
non_empty_paths = list(filter(None, args))
69+
70+
relevant_paths = []
71+
for path in non_empty_paths:
72+
if path.startswith("/"):
73+
relevant_paths = [path]
74+
else:
75+
relevant_paths.append(path)
76+
77+
return "/".join(relevant_paths)

tests/zips_tests.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,11 @@ def empty_parts_are_ignored_when_joining_paths():
2727
assert_equal("a", zips.join_path("a", ""))
2828
assert_equal("b", zips.join_path("", "b"))
2929
assert_equal("a/b", zips.join_path("a", "", "b"))
30-
30+
31+
32+
@istest
33+
def when_joining_paths_then_absolute_paths_ignore_earlier_paths():
34+
assert_equal("/b", zips.join_path("a", "/b"))
35+
assert_equal("/b/c", zips.join_path("a", "/b", "c"))
36+
assert_equal("/b", zips.join_path("/a", "/b"))
37+
assert_equal("/a", zips.join_path("/a"))

0 commit comments

Comments
 (0)