msg299253 - (view) |
Author: Christoph Reiter (lazka) * |
Date: 2017-07-26 16:47 |
On Windows os.path.abspath(" ") == " " While that's not a valid Windows path, similar invalid paths like "" or "?" etc all produce an absolute path. Tested on 2.7 and 3.6 |
|
|
msg299266 - (view) |
Author: Eryk Sun (eryksun) *  |
Date: 2017-07-26 21:47 |
The generic abspath implementation could be moved into the genericpath module, where it will be common to both posixpath and ntpath: def abspath(path): """Return an absolute path.""" path = os.fspath(path) if not isabs(path): if isinstance(path, bytes): cwd = os.getcwdb() else: cwd = os.getcwd() path = join(cwd, path) return normpath(path) Then replace it in ntpath if nt._getfullpathname is defined, but with a fallback to the generic implementation if OSError is raised (e.g. for " "): try: from nt import _getfullpathname except ImportError: pass else: def abspath(path): """Return an absolute path.""" try: return _getfullpathname(path) except OSError: return genericpath.abspath(path) This _getfullpathname version also skips the redundant fspath and normpath calls. |
|
|
msg322633 - (view) |
Author: Steve Dower (steve.dower) *  |
Date: 2018-07-29 12:47 |
New changeset d2e902e4fb304f27e4a72356efbc1fc26be3935d by Steve Dower (Franz Wöllert) in branch 'master': bpo-31047: Fix ntpath.abspath for invalid paths (GH-8544) https://github.com/python/cpython/commit/d2e902e4fb304f27e4a72356efbc1fc26be3935d |
|
|
msg322636 - (view) |
Author: miss-islington (miss-islington) |
Date: 2018-07-29 15:42 |
New changeset 5753b13cb949b939b2b29cec5e2d646f9a30db44 by Miss Islington (bot) in branch '3.7': bpo-31047: Fix ntpath.abspath for invalid paths (GH-8544) https://github.com/python/cpython/commit/5753b13cb949b939b2b29cec5e2d646f9a30db44 |
|
|
msg323229 - (view) |
Author: Steve Dower (steve.dower) *  |
Date: 2018-08-07 00:08 |
New changeset b0bf51b32240369ccb736dc32ff82bb96f375402 by Steve Dower in branch '3.6': bpo-31047: Fix ntpath.abspath for invalid paths (GH-8544) https://github.com/python/cpython/commit/b0bf51b32240369ccb736dc32ff82bb96f375402 |
|
|
msg328322 - (view) |
Author: Tim Graham (Tim.Graham) * |
Date: 2018-10-23 15:32 |
I think this caused a behavior change: Before (Python 3.6.6): >>> from os.path import abspath >>> abspath('/abc/') 'C:\\abc' After (Python 3.6.7): >>> abspath('/abc/') 'C:\\abc\\' This causes a test failure in Django's safe_join() function: https://github.com/django/django/blob/10d82c85aa5f8bd6adff0db49798dd368455cdcf/django/utils/_os.py#L24-L47 https://github.com/django/django/blob/10d82c85aa5f8bd6adff0db49798dd368455cdcf/tests/utils_tests/test_os_utils.py#L10 Traceback (most recent call last): File "C:\Jenkins\workspace\django-windows\database\sqlite3\label\windows\python\Python36\tests\utils_tests\test_os_utils.py", line 10, in test_base_path_ends_with_sep drive, path = os.path.splitdrive(safe_join("/abc/", "abc")) File "C:\Jenkins\workspace\django-windows\database\sqlite3\label\windows\python\Python36\django\utils\_os.py", line 46, in safe_join 'component ({})'.format(final_path, base_path)) django.core.exceptions.SuspiciousFileOperation: The joined path (C:\abc\abc) is located outside of the base path component (C:\abc\) |
|
|
msg328328 - (view) |
Author: Steve Dower (steve.dower) *  |
Date: 2018-10-23 17:43 |
Agreed, it no longer matches os.normpath()'s declared behavior by not trimming the end separator. It's obviously too late for the current release (I'd hope Django is one of the projects running tests against RC's, but I guess not :( ), but I think we can fix it for the next updates on all versions. Patches welcome. |
|
|
msg328448 - (view) |
Author: Steve Dower (steve.dower) *  |
Date: 2018-10-25 15:26 |
New changeset d03b7757811ae51277f8ed399a9a0fd78dfd3425 by Steve Dower (Tim Graham) in branch 'master': bpo-31047: Fix ntpath.abspath to trim ending separator (GH-10082) https://github.com/python/cpython/commit/d03b7757811ae51277f8ed399a9a0fd78dfd3425 |
|
|
msg328463 - (view) |
Author: Steve Dower (steve.dower) *  |
Date: 2018-10-25 17:46 |
New changeset a7ffb663953bc84452af1e5f4089359d54e226b5 by Steve Dower in branch '3.7': [3.7] bpo-31047: Fix ntpath.abspath to trim ending separator (GH-10082) https://github.com/python/cpython/commit/a7ffb663953bc84452af1e5f4089359d54e226b5 |
|
|
msg328464 - (view) |
Author: Steve Dower (steve.dower) *  |
Date: 2018-10-25 17:46 |
New changeset 4aa1fda7069642c21c1ee570c4ba44442a657e5e by Steve Dower in branch '3.6': bpo-31047: Fix ntpath.abspath to trim ending separator (GH-10082) https://github.com/python/cpython/commit/4aa1fda7069642c21c1ee570c4ba44442a657e5e |
|
|
msg328465 - (view) |
Author: Steve Dower (steve.dower) *  |
Date: 2018-10-25 17:47 |
Thanks, Tim! |
|
|