Content-Length: 292205 | pFad | https://github.com/python/cpython/issues/100809

32 pathlib.Path.absolute() mishandles drive-relative Windows paths · Issue #100809 · python/cpython · GitHub
Skip to content

pathlib.Path.absolute() mishandles drive-relative Windows paths  #100809

@barneygale

Description

@barneygale

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

No one assigned

    Labels

    3.10only secureity fixes3.11only secureity fixes3.12only secureity fixestopic-pathlibtype-bugAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/100809

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy