bpo-31047: Fix ntpath.abspath to trim ending separator (GH-10082) · python/cpython@4aa1fda (original) (raw)
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -545,8 +545,8 @@ def _abspath_fallback(path): | ||
545 | 545 | def abspath(path): |
546 | 546 | """Return the absolute version of a path.""" |
547 | 547 | try: |
548 | -return _getfullpathname(path) | |
549 | -except OSError: | |
548 | +return normpath(_getfullpathname(path)) | |
549 | +except (OSError, ValueError): | |
550 | 550 | return _abspath_fallback(path) |
551 | 551 | |
552 | 552 | # realpath is a no-op on systems without islink support |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -307,6 +307,8 @@ def test_abspath(self): | ||
307 | 307 | tester('ntpath.abspath("")', cwd_dir) |
308 | 308 | tester('ntpath.abspath(" ")', cwd_dir + "\\ ") |
309 | 309 | tester('ntpath.abspath("?")', cwd_dir + "\\?") |
310 | +drive, _ = ntpath.splitdrive(cwd_dir) | |
311 | +tester('ntpath.abspath("/abc/")', drive + "\\abc") | |
310 | 312 | except ImportError: |
311 | 313 | self.skipTest('nt module not available') |
312 | 314 |
Original file line number | Diff line number | Diff 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. |