mirror of
https://github.com/python/cpython.git
synced 2025-07-19 01:05:26 +00:00
GH-78079: Fix UNC device path root normalization in pathlib (GH-102003)
We no longer add a root to device paths such as `//./PhysicalDrive0`, `//?/BootPartition` and `//./c:` while normalizing. We also avoid adding a root to incomplete UNC share paths, like `//`, `//a` and `//a/`. Co-authored-by: Eryk Sun <eryksun@gmail.com>
This commit is contained in:
parent
7c1b0a46c6
commit
8af8f52d17
4 changed files with 43 additions and 3 deletions
|
@ -322,9 +322,14 @@ class PurePath(object):
|
|||
if altsep:
|
||||
path = path.replace(altsep, sep)
|
||||
drv, root, rel = cls._flavour.splitroot(path)
|
||||
if drv.startswith(sep):
|
||||
# pathlib assumes that UNC paths always have a root.
|
||||
root = sep
|
||||
if not root and drv.startswith(sep) and not drv.endswith(sep):
|
||||
drv_parts = drv.split(sep)
|
||||
if len(drv_parts) == 4 and drv_parts[2] not in '?.':
|
||||
# e.g. //server/share
|
||||
root = sep
|
||||
elif len(drv_parts) == 6:
|
||||
# e.g. //?/unc/server/share
|
||||
root = sep
|
||||
parsed = [sys.intern(str(x)) for x in rel.split(sep) if x and x != '.']
|
||||
return drv, root, parsed
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue