summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-01-30 17:50:48 +0200
committerBerker Peksag <berker.peksag@gmail.com>2016-01-30 17:50:48 +0200
commitfa2eb37603d8d9346aa7f6749f24a5529b2b45b7 (patch)
tree90fc1aa0d130424e436bd1a6758080b54aee6265
parent0fa893096e5d3e411964d015f07c6c004fa8af8f (diff)
downloadcpython-fa2eb37603d8d9346aa7f6749f24a5529b2b45b7.tar.gz
Issue #23076: Path.glob() now raises a ValueError if it's called with an
invalid pattern. Patch by Thomas Nyberg.
-rw-r--r--Lib/pathlib.py2
-rw-r--r--Lib/test/test_pathlib.py5
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
4 files changed, 11 insertions, 0 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index bbac773228..5169ff5e63 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -1065,6 +1065,8 @@ class Path(PurePath):
"""Iterate over this subtree and yield all existing files (of any
kind, including directories) matching the given pattern.
"""
+ if not pattern:
+ raise ValueError("Unacceptable pattern: {!r}".format(pattern))
pattern = self._flavour.casefold(pattern)
drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
if drv or root:
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py
index 490d423ca3..b03fee018f 100644
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -1969,6 +1969,11 @@ class PathTest(_BasePathTest, unittest.TestCase):
else:
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
class PosixPathTest(_BasePathTest, unittest.TestCase):
diff --git a/Misc/ACKS b/Misc/ACKS
index 28e45d38bf..426d19f714 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1038,6 +1038,7 @@ Neal Norwitz
Mikhail Novikov
Michal Nowikowski
Steffen Daode Nurpmeso
+Thomas Nyberg
Nigel O'Brian
John O'Connor
Kevin O'Connor
diff --git a/Misc/NEWS b/Misc/NEWS
index 11ce59a768..a95d2a06c0 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -73,6 +73,9 @@ Library
- Issue #26202: copy.deepcopy() now correctly copies range() objects with
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 #26227: On Windows, getnameinfo(), gethostbyaddr() and