[Python-checkins] [3.7] bpo-31047: Fix ntpath.abspath to trim ending separator (GH-10082)

Steve Dower webhook-mailer at python.org
Thu Oct 25 13:46:28 EDT 2018


https://github.com/python/cpython/commit/a7ffb663953bc84452af1e5f4089359d54e226b5
commit: a7ffb663953bc84452af1e5f4089359d54e226b5
branch: 3.7
author: Steve Dower <steve.dower at microsoft.com>
committer: GitHub <noreply at github.com>
date: 2018-10-25T13:46:23-04:00
summary:

[3.7] bpo-31047: Fix ntpath.abspath to trim ending separator (GH-10082)

files:
A Misc/NEWS.d/next/Library/2018-10-25-09-37-03.bpo-31047.kBbX8r.rst
M Lib/ntpath.py
M Lib/test/test_ntpath.py

diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index f0e03a2f496a..3c820b5d0eb7 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -523,8 +523,8 @@ def _abspath_fallback(path):
     def abspath(path):
         """Return the absolute version of a path."""
         try:
-            return _getfullpathname(path)
-        except OSError:
+            return normpath(_getfullpathname(path))
+        except (OSError, ValueError):
             return _abspath_fallback(path)
 
 # realpath is a no-op on systems without islink support
diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py
index 907ca7edbead..6e31b6441122 100644
--- a/Lib/test/test_ntpath.py
+++ b/Lib/test/test_ntpath.py
@@ -284,6 +284,8 @@ def test_abspath(self):
             tester('ntpath.abspath("")', cwd_dir)
             tester('ntpath.abspath(" ")', cwd_dir + "\\ ")
             tester('ntpath.abspath("?")', cwd_dir + "\\?")
+            drive, _ = ntpath.splitdrive(cwd_dir)
+            tester('ntpath.abspath("/abc/")', drive + "\\abc")
 
     def test_relpath(self):
         tester('ntpath.relpath("a")', 'a')
diff --git a/Misc/NEWS.d/next/Library/2018-10-25-09-37-03.bpo-31047.kBbX8r.rst b/Misc/NEWS.d/next/Library/2018-10-25-09-37-03.bpo-31047.kBbX8r.rst
new file mode 100644
index 000000000000..1e47bf4174e7
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-10-25-09-37-03.bpo-31047.kBbX8r.rst
@@ -0,0 +1,2 @@
+Fix ``ntpath.abspath`` regression where it didn't remove a trailing
+separator on Windows. Patch by Tim Graham.



More information about the Python-checkins mailing list