Skip to content
Merged
Prev Previous commit
Next Next commit
Fix handling of UNC paths with incomplete drives in glob(), walk(), etc.
  • Loading branch information
barneygale committed Mar 10, 2023
commit 36623c0b3439089d7d706eeae565f928c0fb7b88
11 changes: 9 additions & 2 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,15 @@ def __new__(cls, *args, **kwargs):
def _make_child_relpath(self, part):
# This is an optimization used for dir walking. `part` must be
# a single part relative to this path.
parts = self._parts + [part]
return self._from_parsed_parts(self._drv, self._root, parts)
drv = self._drv
root = self._root
parts = self._parts
if drv and not root and not parts:
sep = self._flavour.sep
if drv.startswith(sep) and not drv.endswith(sep):
# Incomplete UNC drive like '//foo'.
return self._from_parts([self, part])
return self._from_parsed_parts(drv, root, parts + [part])

def __enter__(self):
# In previous versions of pathlib, __exit__() marked this path as
Expand Down