[Python-checkins] GH-103220: Fix `ntpath.join()` of partial UNC drive with trailing slash (GH-103221)
barneygale
webhook-mailer at python.org
Tue Apr 11 12:26:53 EDT 2023
https://github.com/python/cpython/commit/b57105ae33e1f61e6bdf0eec45c4135d067b9b22
commit: b57105ae33e1f61e6bdf0eec45c4135d067b9b22
branch: main
author: Barney Gale <barney.gale at gmail.com>
committer: barneygale <barney.gale at gmail.com>
date: 2023-04-11T17:26:45+01:00
summary:
GH-103220: Fix `ntpath.join()` of partial UNC drive with trailing slash (GH-103221)
files:
A Misc/NEWS.d/next/Library/2023-04-03-21-08-53.gh-issue-103220.OW_Bj5.rst
M Lib/ntpath.py
M Lib/test/test_ntpath.py
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index 6e2da79c85d3..0f3674fe11ee 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -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):
diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py
index 4e755d154039..42b9587ca181 100644
--- a/Lib/test/test_ntpath.py
+++ b/Lib/test/test_ntpath.py
@@ -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')
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
index 000000000000..9cf26c26873b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-04-03-21-08-53.gh-issue-103220.OW_Bj5.rst
@@ -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.
More information about the Python-checkins
mailing list