diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-07-19 17:18:18 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-07-19 17:18:18 (GMT) |
commit | 1bdd0f255997ded18117e0e33916b67bd023cc47 (patch) | |
tree | 60b3cccc43f2047baed34c103969871c16e64707 /Lib/ntpath.py | |
parent | acd32d3be542987078c65a8a34d7844cfa7ebbe8 (diff) | |
download | cpython-1bdd0f255997ded18117e0e33916b67bd023cc47.zip cpython-1bdd0f255997ded18117e0e33916b67bd023cc47.tar.gz cpython-1bdd0f255997ded18117e0e33916b67bd023cc47.tar.bz2 |
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.
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r-- | Lib/ntpath.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py index 71027c1..13de59b 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -42,12 +42,22 @@ def join(a, *p): """Join two or more pathname components, inserting "\\" as needed""" path = a for b in p: - if isabs(b): - path = b - elif path == '' or path[-1:] in '/\\:': - path = path + b - else: - path = path + "\\" + b + # If path is a raw drive letter (e.g. "C:"), and b doesn't start + # with a drive letter, path+b is correct, and regardless of whether + # b is absolute on its own. + if len(path) == 2 and path[-1] == ":" and splitdrive(b)[0] == "": + pass + + # 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 |