Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4a208e4

Browse files
committed
Issue #23076: Path.glob() now raises a ValueError if it's called with an
invalid pattern. Patch by Thomas Nyberg.
1 parent ef41077 commit 4a208e4

4 files changed

Lines changed: 11 additions & 0 deletions

File tree

Lib/pathlib.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,8 @@ def glob(self, pattern):
10651065
"""Iterate over this subtree and yield all existing files (of any
10661066
kind, including directories) matching the given pattern.
10671067
"""
1068+
if not pattern:
1069+
raise ValueError("Unacceptable pattern: {!r}".format(pattern))
10681070
pattern = self._flavour.casefold(pattern)
10691071
drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
10701072
if drv or root:

Lib/test/test_pathlib.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,6 +1969,11 @@ def test_unsupported_flavour(self):
19691969
else:
19701970
self.assertRaises(NotImplementedError, pathlib.WindowsPath)
19711971

1972+
def test_glob_empty_pattern(self):
1973+
p = self.cls()
1974+
with self.assertRaisesRegex(ValueError, 'Unacceptable pattern'):
1975+
list(p.glob(''))
1976+
19721977

19731978
@only_posix
19741979
class PosixPathTest(_BasePathTest, unittest.TestCase):

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,7 @@ Neal Norwitz
10381038
Mikhail Novikov
10391039
Michal Nowikowski
10401040
Steffen Daode Nurpmeso
1041+
Thomas Nyberg
10411042
Nigel O'Brian
10421043
John O'Connor
10431044
Kevin O'Connor

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ Library
7373
- Issue #26202: copy.deepcopy() now correctly copies range() objects with
7474
non-atomic attributes.
7575

76+
- Issue #23076: Path.glob() now raises a ValueError if it's called with an
77+
invalid pattern. Patch by Thomas Nyberg.
78+
7679
- Issue #19883: Fixed possible integer overflows in zipimport.
7780

7881
- Issue #26227: On Windows, getnameinfo(), gethostbyaddr() and

0 commit comments

Comments
 (0)