summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2023-04-14 20:55:41 (GMT)
committerGitHub <noreply@github.com>2023-04-14 20:55:41 (GMT)
commit8af8f52d175959f03cf4a2786b6a81ec09e15e95 (patch)
tree8848581a801af299c17343a997acb5f1a06c9f40 /Lib/pathlib.py
parent7c1b0a46c61f8bf8e2039bba1bff11b6ae20e56b (diff)
downloadcpython-8af8f52d175959f03cf4a2786b6a81ec09e15e95.zip
cpython-8af8f52d175959f03cf4a2786b6a81ec09e15e95.tar.gz
cpython-8af8f52d175959f03cf4a2786b6a81ec09e15e95.tar.bz2
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>
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r--Lib/pathlib.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 4ae1fae..f43f01e 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -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