Skip to content

Commit a7ffb66

Browse files
authored
[3.7] bpo-31047: Fix ntpath.abspath to trim ending separator (GH-10082)
1 parent 69a3f15 commit a7ffb66

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

Lib/ntpath.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@ def _abspath_fallback(path):
523523
def abspath(path):
524524
"""Return the absolute version of a path."""
525525
try:
526-
return _getfullpathname(path)
527-
except OSError:
526+
return normpath(_getfullpathname(path))
527+
except (OSError, ValueError):
528528
return _abspath_fallback(path)
529529

530530
# realpath is a no-op on systems without islink support

Lib/test/test_ntpath.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ def test_abspath(self):
284284
tester('ntpath.abspath("")', cwd_dir)
285285
tester('ntpath.abspath(" ")', cwd_dir + "\\ ")
286286
tester('ntpath.abspath("?")', cwd_dir + "\\?")
287+
drive, _ = ntpath.splitdrive(cwd_dir)
288+
tester('ntpath.abspath("/abc/")', drive + "\\abc")
287289

288290
def test_relpath(self):
289291
tester('ntpath.relpath("a")', 'a')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``ntpath.abspath`` regression where it didn't remove a trailing
2+
separator on Windows. Patch by Tim Graham.

0 commit comments

Comments
 (0)