mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00
GH-44626, GH-105476: Fix ntpath.isabs()
handling of part-absolute paths (#113829)
On Windows, `os.path.isabs()` now returns `False` when given a path that starts with exactly one (back)slash. This is more compatible with other functions in `os.path`, and with Microsoft's own documentation. Also adjust `pathlib.PureWindowsPath.is_absolute()` to call `ntpath.isabs()`, which corrects its handling of partial UNC/device paths like `//foo`. Co-authored-by: Jon Foster <jon@jon-foster.co.uk>
This commit is contained in:
parent
dac1da2121
commit
e4ff131e01
9 changed files with 51 additions and 33 deletions
|
@ -1,5 +1,4 @@
|
|||
import functools
|
||||
import ntpath
|
||||
import posixpath
|
||||
from errno import ENOENT, ENOTDIR, EBADF, ELOOP, EINVAL
|
||||
from stat import S_ISDIR, S_ISLNK, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO
|
||||
|
@ -373,10 +372,7 @@ class PurePathBase:
|
|||
def is_absolute(self):
|
||||
"""True if the path is absolute (has both a root and, if applicable,
|
||||
a drive)."""
|
||||
if self.pathmod is ntpath:
|
||||
# ntpath.isabs() is defective - see GH-44626.
|
||||
return bool(self.drive and self.root)
|
||||
elif self.pathmod is posixpath:
|
||||
if self.pathmod is posixpath:
|
||||
# Optimization: work with raw paths on POSIX.
|
||||
for path in self._raw_paths:
|
||||
if path.startswith('/'):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue