Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1bdd0f2

Browse files
committed
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.
1 parent acd32d3 commit 1bdd0f2

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

Lib/ntpath.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,22 @@ def join(a, *p):
4242
"""Join two or more pathname components, inserting "\\" as needed"""
4343
path = a
4444
for b in p:
45-
if isabs(b):
46-
path = b
47-
elif path == '' or path[-1:] in '/\\:':
48-
path = path + b
49-
else:
50-
path = path + "\\" + b
45+
# If path is a raw drive letter (e.g. "C:"), and b doesn't start
46+
# with a drive letter, path+b is correct, and regardless of whether
47+
# b is absolute on its own.
48+
if len(path) == 2 and path[-1] == ":" and splitdrive(b)[0] == "":
49+
pass
50+
51+
# In any other case, if b is absolute it wipes out the path so far.
52+
elif isabs(b) or path == "":
53+
path = ""
54+
55+
# Else make sure a separator appears between the pieces.
56+
elif path[-1:] not in "/\\":
57+
b = "\\" + b
58+
59+
path += b
60+
5161
return path
5262

5363

0 commit comments

Comments
 (0)