Commit 396cbd6d authored by Berker Peksag's avatar Berker Peksag

Issue #23076: Path.glob() now raises a ValueError if it's called with an

invalid pattern.

Patch by Thomas Nyberg.
parents 5586ba76 4a208e44
...@@ -1065,6 +1065,8 @@ class Path(PurePath): ...@@ -1065,6 +1065,8 @@ class Path(PurePath):
"""Iterate over this subtree and yield all existing files (of any """Iterate over this subtree and yield all existing files (of any
kind, including directories) matching the given pattern. kind, including directories) matching the given pattern.
""" """
if not pattern:
raise ValueError("Unacceptable pattern: {!r}".format(pattern))
pattern = self._flavour.casefold(pattern) pattern = self._flavour.casefold(pattern)
drv, root, pattern_parts = self._flavour.parse_parts((pattern,)) drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
if drv or root: if drv or root:
......
...@@ -1969,6 +1969,11 @@ class PathTest(_BasePathTest, unittest.TestCase): ...@@ -1969,6 +1969,11 @@ class PathTest(_BasePathTest, unittest.TestCase):
else: else:
self.assertRaises(NotImplementedError, pathlib.WindowsPath) self.assertRaises(NotImplementedError, pathlib.WindowsPath)
def test_glob_empty_pattern(self):
p = self.cls()
with self.assertRaisesRegex(ValueError, 'Unacceptable pattern'):
list(p.glob(''))
@only_posix @only_posix
class PosixPathTest(_BasePathTest, unittest.TestCase): class PosixPathTest(_BasePathTest, unittest.TestCase):
......
...@@ -1042,6 +1042,7 @@ Neal Norwitz ...@@ -1042,6 +1042,7 @@ Neal Norwitz
Mikhail Novikov Mikhail Novikov
Michal Nowikowski Michal Nowikowski
Steffen Daode Nurpmeso Steffen Daode Nurpmeso
Thomas Nyberg
Nigel O'Brian Nigel O'Brian
John O'Connor John O'Connor
Kevin O'Connor Kevin O'Connor
......
...@@ -166,6 +166,9 @@ Library ...@@ -166,6 +166,9 @@ Library
- Issue #26202: copy.deepcopy() now correctly copies range() objects with - Issue #26202: copy.deepcopy() now correctly copies range() objects with
non-atomic attributes. non-atomic attributes.
- Issue #23076: Path.glob() now raises a ValueError if it's called with an
invalid pattern. Patch by Thomas Nyberg.
- Issue #19883: Fixed possible integer overflows in zipimport. - Issue #19883: Fixed possible integer overflows in zipimport.
- Issue #26227: On Windows, getnameinfo(), gethostbyaddr() and - Issue #26227: On Windows, getnameinfo(), gethostbyaddr() and
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment