[issue43455] pathlib mistakenly assumes os.getcwd() is a resolved path in Windows

Eryk Sun report at bugs.python.org
Tue Mar 9 18:05:56 EST 2021


New submission from Eryk Sun <eryksun at gmail.com>:

pathlib._WindowsFlavour.resolve() mistakenly assume that os.getcwd() returns a resolved path in Windows:

    s = str(path)
    if not s:
        return os.getcwd()

I don't think this is a practical problem since `str(path)` should never be an empty string. But if there is a concern that the result is an empty string, the code should use `s = str(path) or '.'`, and resolve "." like any other relative path.

In POSIX the result of getcwd() "shall contain no components that are dot or dot-dot, or are symbolic links". In Windows, os.getcwd() calls WinAPI GetCurrentDirectoryW(), which returns a fully-qualified path that may contain symbolic components that would be resolved in a final path. This includes filesystem symlinks and bind mounts (junctions), as well as mapped and substitute drives (i.e. drives that resolve to a filesystem directory instead of a volume device).

----------
components: Library (Lib), Windows
messages: 388393
nosy: eryksun, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: pathlib mistakenly assumes os.getcwd() is a resolved path in Windows
type: behavior
versions: Python 3.10, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43455>
_______________________________________


More information about the Python-bugs-list mailing list