Commit 1bdd0f25 authored by Tim Peters's avatar Tim Peters

SF bug #44271: os.path.expanduser problem w/o HOME set.

This is a Windows-specific glitch that's really due to that, e.g.,
ntpath.join("c:", "/abc") returned "/abc" instead of "c:/abc".  Made
join smarter.
Bugfix candidate.
parent acd32d3b
...@@ -42,12 +42,22 @@ def join(a, *p): ...@@ -42,12 +42,22 @@ def join(a, *p):
"""Join two or more pathname components, inserting "\\" as needed""" """Join two or more pathname components, inserting "\\" as needed"""
path = a path = a
for b in p: for b in p:
if isabs(b): # If path is a raw drive letter (e.g. "C:"), and b doesn't start
path = b # with a drive letter, path+b is correct, and regardless of whether
elif path == '' or path[-1:] in '/\\:': # b is absolute on its own.
path = path + b if len(path) == 2 and path[-1] == ":" and splitdrive(b)[0] == "":
else: pass
path = path + "\\" + b
# In any other case, if b is absolute it wipes out the path so far.
elif isabs(b) or path == "":
path = ""
# Else make sure a separator appears between the pieces.
elif path[-1:] not in "/\\":
b = "\\" + b
path += b
return path return path
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment