Skip to content

py.path.local('/').join('foo') should return '/foo' not '//foo'. #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
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
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.4.34
======

- fix #127 - path.join() no longer returns double slashes in order to ease comparing
to avoid breaking in non-posix unix envs like cygwin
- fix python37 compatibility of path.sysfind on windows by correctly replacing vars

1.4.34
Expand Down
5 changes: 4 additions & 1 deletion py/_path/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,16 @@ def join(self, *args, **kwargs):
strargs = newargs
break
newargs.insert(0, arg)
# special case for when we have e.g. strpath == "/"
actual_sep = "" if strpath.endswith(sep) else sep
for arg in strargs:
arg = arg.strip(sep)
if iswin32:
# allow unix style paths even on windows.
arg = arg.strip('/')
arg = arg.replace('/', sep)
strpath = strpath + sep + arg
strpath = strpath + actual_sep + arg
actual_sep = sep
obj = object.__new__(self.__class__)
obj.strpath = normpath(strpath)
return obj
Expand Down
2 changes: 1 addition & 1 deletion testing/path/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ def test_commondir_nocommon(self, path1):
def test_join_to_root(self, path1):
root = path1.parts()[0]
assert len(str(root)) == 1
assert str(root.join('a')) == '//a' # posix allows two slashes
assert str(root.join('a')) == '/a'

def test_join_root_to_root_with_no_abs(self, path1):
nroot = path1.join('/')
Expand Down