-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Closed
Labels
3.10only security fixesonly security fixes3.11only security fixesonly security fixes3.12only security fixesonly security fixestopic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Windows has one current directory per drive, and supports drive-relative paths like 'X:' and 'X:foo.txt'. This makes a conversion from relative to absolute paths more complicated than simply prepending a (single) current directory.
It's correctly handled in ntpath.abspath()
by calling NT's GetFullPathNameW()
function. But in pathlib we simply prepend os.getcwd()
, leading to incorrect results:
>>> import os, nt, pathlib
>>> os.chdir('Z:/build')
>>> os.chdir('C:/')
>>> os.path.abspath('Z:')
'Z:\\build'
>>> nt._getfullpathname('Z:')
'Z:\\build'
>>> pathlib.Path('Z:').absolute()
WindowsPath('Z:')
This bug is present in all versions of CPython pathlib. We can't fix it by calling abspath()
because it will also normalize the path, eliding '..' parts.
Linked PRs
Metadata
Metadata
Assignees
Labels
3.10only security fixesonly security fixes3.11only security fixesonly security fixes3.12only security fixesonly security fixestopic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error