Skip to content

Commit

Permalink
pythonGH-103220: Fix ntpath.join() of partial UNC drive with traili…
Browse files Browse the repository at this point in the history
…ng slash (pythonGH-103221)
  • Loading branch information
barneygale authored and warsaw committed Apr 11, 2023
1 parent 76224c8 commit 0878460
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/ntpath.py
Expand Up @@ -142,7 +142,7 @@ def join(path, *paths):
result_path = result_path + p_path
## add separator between UNC and non-absolute path
if (result_path and not result_root and
result_drive and result_drive[-1:] != colon):
result_drive and result_drive[-1:] not in colon + seps):
return result_drive + sep + result_path
return result_drive + result_root + result_path
except (TypeError, AttributeError, BytesWarning):
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_ntpath.py
Expand Up @@ -300,6 +300,11 @@ def test_join(self):
tester("ntpath.join('//computer/share', 'a', 'b')", '//computer/share\\a\\b')
tester("ntpath.join('//computer/share', 'a/b')", '//computer/share\\a/b')

tester("ntpath.join('\\\\', 'computer')", '\\\\computer')
tester("ntpath.join('\\\\computer\\', 'share')", '\\\\computer\\share')
tester("ntpath.join('\\\\computer\\share\\', 'a')", '\\\\computer\\share\\a')
tester("ntpath.join('\\\\computer\\share\\a\\', 'b')", '\\\\computer\\share\\a\\b')

def test_normpath(self):
tester("ntpath.normpath('A//////././//.//B')", r'A\B')
tester("ntpath.normpath('A/./B')", r'A\B')
Expand Down
@@ -0,0 +1,2 @@
Fix issue where :func:`os.path.join` added a slash when joining onto an
incomplete UNC drive with a trailing slash on Windows.

0 comments on commit 0878460

Please sign in to comment.