Skip to content

Commit b57105a

Browse files
authored
pythonGH-103220: Fix ntpath.join() of partial UNC drive with trailing slash (pythonGH-103221)
1 parent 50b4b15 commit b57105a

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

Lib/ntpath.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def join(path, *paths):
142142
result_path = result_path + p_path
143143
## add separator between UNC and non-absolute path
144144
if (result_path and not result_root and
145-
result_drive and result_drive[-1:] != colon):
145+
result_drive and result_drive[-1:] not in colon + seps):
146146
return result_drive + sep + result_path
147147
return result_drive + result_root + result_path
148148
except (TypeError, AttributeError, BytesWarning):

Lib/test/test_ntpath.py

+5
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ def test_join(self):
300300
tester("ntpath.join('//computer/share', 'a', 'b')", '//computer/share\\a\\b')
301301
tester("ntpath.join('//computer/share', 'a/b')", '//computer/share\\a/b')
302302

303+
tester("ntpath.join('\\\\', 'computer')", '\\\\computer')
304+
tester("ntpath.join('\\\\computer\\', 'share')", '\\\\computer\\share')
305+
tester("ntpath.join('\\\\computer\\share\\', 'a')", '\\\\computer\\share\\a')
306+
tester("ntpath.join('\\\\computer\\share\\a\\', 'b')", '\\\\computer\\share\\a\\b')
307+
303308
def test_normpath(self):
304309
tester("ntpath.normpath('A//////././//.//B')", r'A\B')
305310
tester("ntpath.normpath('A/./B')", r'A\B')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix issue where :func:`os.path.join` added a slash when joining onto an
2+
incomplete UNC drive with a trailing slash on Windows.

0 commit comments

Comments
 (0)