-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Windows: os.path.isabs(os.path.abspath(" ")) == False #75230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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 |
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 " "):
This _getfullpathname version also skips the redundant fspath and normpath calls. |
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 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\) |
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. |
Thanks, Tim! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: