]> granicus.if.org Git - python/commitdiff
Issue #23076: Path.glob() now raises a ValueError if it's called with an
authorBerker Peksag <berker.peksag@gmail.com>
Sat, 30 Jan 2016 15:50:48 +0000 (17:50 +0200)
committerBerker Peksag <berker.peksag@gmail.com>
Sat, 30 Jan 2016 15:50:48 +0000 (17:50 +0200)
invalid pattern.

Patch by Thomas Nyberg.

Lib/pathlib.py
Lib/test/test_pathlib.py
Misc/ACKS
Misc/NEWS

index bbac77322853144e82487aebcc67e62ff0d1114a..5169ff5e633516a3faf69debc8acaecd02635234 100644 (file)
@@ -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:
index 490d423ca3e3361261c568219d6a24113a7c575f..b03fee018f3c97c029d2c7d5e1ffbd11202dfaa9 100644 (file)
@@ -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):
index 28e45d38bfffb997dc5c92cf9bc4d3f334e935fb..426d19f714c0d810bf3ae865fa92aea4918025c7 100644 (file)
--- 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
index 11ce59a768710d6cbce577afff7e2a204ffbab74..a95d2a06c058679e501591b5a5091103490c126d 100644 (file)
--- 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