GH-103220: Fix `ntpath.join()` of partial UNC drive with trailing slash (GH-103221)

This commit is contained in:
Barney Gale 2023-04-11 17:26:45 +01:00 committed by GitHub
parent 50b4b15984
commit b57105ae33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 1 deletions

View File

@ -142,7 +142,7 @@ def join(path, *paths):
result_path = result_path + p_path result_path = result_path + p_path
## add separator between UNC and non-absolute path ## add separator between UNC and non-absolute path
if (result_path and not result_root and 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 + sep + result_path
return result_drive + result_root + result_path return result_drive + result_root + result_path
except (TypeError, AttributeError, BytesWarning): except (TypeError, AttributeError, BytesWarning):

View File

@ -300,6 +300,11 @@ class TestNtpath(NtpathTestCase):
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/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): def test_normpath(self):
tester("ntpath.normpath('A//////././//.//B')", r'A\B') tester("ntpath.normpath('A//////././//.//B')", r'A\B')
tester("ntpath.normpath('A/./B')", r'A\B') tester("ntpath.normpath('A/./B')", r'A\B')

View File

@ -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.