changeset: 100123:35bf4f9e68f3 branch: 3.5 parent: 100120:a1044c05a6dc user: Berker Peksag date: Sat Jan 30 17:50:48 2016 +0200 files: Lib/pathlib.py Lib/test/test_pathlib.py Misc/ACKS Misc/NEWS description: Issue #23076: Path.glob() now raises a ValueError if it's called with an invalid pattern. Patch by Thomas Nyberg. diff -r a1044c05a6dc -r 35bf4f9e68f3 Lib/pathlib.py --- a/Lib/pathlib.py Sat Jan 30 12:24:31 2016 +0200 +++ b/Lib/pathlib.py Sat Jan 30 17:50:48 2016 +0200 @@ -1065,6 +1065,8 @@ """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 -r a1044c05a6dc -r 35bf4f9e68f3 Lib/test/test_pathlib.py --- a/Lib/test/test_pathlib.py Sat Jan 30 12:24:31 2016 +0200 +++ b/Lib/test/test_pathlib.py Sat Jan 30 17:50:48 2016 +0200 @@ -1969,6 +1969,11 @@ 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 -r a1044c05a6dc -r 35bf4f9e68f3 Misc/ACKS --- a/Misc/ACKS Sat Jan 30 12:24:31 2016 +0200 +++ b/Misc/ACKS Sat Jan 30 17:50:48 2016 +0200 @@ -1038,6 +1038,7 @@ Mikhail Novikov Michal Nowikowski Steffen Daode Nurpmeso +Thomas Nyberg Nigel O'Brian John O'Connor Kevin O'Connor diff -r a1044c05a6dc -r 35bf4f9e68f3 Misc/NEWS --- a/Misc/NEWS Sat Jan 30 12:24:31 2016 +0200 +++ b/Misc/NEWS Sat Jan 30 17:50:48 2016 +0200 @@ -73,6 +73,9 @@ - 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