]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-103220: Fix `ntpath.join()` of partial UNC drive with trailing slash (GH-103221)
authorBarney Gale <barney.gale@gmail.com>
Tue, 11 Apr 2023 16:26:45 +0000 (17:26 +0100)
committerGitHub <noreply@github.com>
Tue, 11 Apr 2023 16:26:45 +0000 (17:26 +0100)
Lib/ntpath.py
Lib/test/test_ntpath.py
Misc/NEWS.d/next/Library/2023-04-03-21-08-53.gh-issue-103220.OW_Bj5.rst [new file with mode: 0644]

index 6e2da79c85d3f086549de2b6daaa5c9718410726..0f3674fe11eecda16261d5cee674be55bd4639f6 100644 (file)
@@ -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):
index 4e755d15403916a8286f1ac919465178eb1ed4fb..42b9587ca18107d355f9991587daa67e83966cbc 100644 (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')", '\\\\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')
diff --git a/Misc/NEWS.d/next/Library/2023-04-03-21-08-53.gh-issue-103220.OW_Bj5.rst b/Misc/NEWS.d/next/Library/2023-04-03-21-08-53.gh-issue-103220.OW_Bj5.rst
new file mode 100644 (file)
index 0000000..9cf26c2
--- /dev/null
@@ -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.