Skip to content

Commit 4aa1fda

Browse files
authored
bpo-31047: Fix ntpath.abspath to trim ending separator (GH-10082)
1 parent 9fd92af commit 4aa1fda

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
@@ -545,8 +545,8 @@ def _abspath_fallback(path):
545545
def abspath(path):
546546
"""Return the absolute version of a path."""
547547
try:
548-
return _getfullpathname(path)
549-
except OSError:
548+
return normpath(_getfullpathname(path))
549+
except (OSError, ValueError):
550550
return _abspath_fallback(path)
551551

552552
# 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
@@ -307,6 +307,8 @@ def test_abspath(self):
307307
tester('ntpath.abspath("")', cwd_dir)
308308
tester('ntpath.abspath(" ")', cwd_dir + "\\ ")
309309
tester('ntpath.abspath("?")', cwd_dir + "\\?")
310+
drive, _ = ntpath.splitdrive(cwd_dir)
311+
tester('ntpath.abspath("/abc/")', drive + "\\abc")
310312
except ImportError:
311313
self.skipTest('nt module not available')
312314

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)