summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-12-16 12:55:47 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-12-16 12:55:47 (GMT)
commit124ee8b1abb8f9d5b03eae20abb9405ce3fa5d7b (patch)
tree8ac2899e71dee307c2e9cfbb0941e801feac4368 /Lib
parent646c7b50860a5171a127f01a511bfc887a0cb72e (diff)
downloadcpython-124ee8b1abb8f9d5b03eae20abb9405ce3fa5d7b.zip
cpython-124ee8b1abb8f9d5b03eae20abb9405ce3fa5d7b.tar.gz
cpython-124ee8b1abb8f9d5b03eae20abb9405ce3fa5d7b.tar.bz2
Issue #16626: Fix infinite recursion in glob.glob() on Windows when the pattern contains a wildcard in the drive or UNC path.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/glob.py5
-rw-r--r--Lib/test/test_glob.py9
2 files changed, 13 insertions, 1 deletions
diff --git a/Lib/glob.py b/Lib/glob.py
index d6ddaad..0aee605 100644
--- a/Lib/glob.py
+++ b/Lib/glob.py
@@ -38,7 +38,10 @@ def iglob(pathname):
for name in glob1(os.curdir, basename):
yield name
return
- if has_magic(dirname):
+ # `os.path.split()` returns the argument itself as a dirname if it is a
+ # drive or UNC path. Prevent an infinite recursion if a drive or UNC path
+ # contains magic characters (i.e. r'\\?\C:').
+ if dirname != pathname and has_magic(dirname):
dirs = iglob(dirname)
else:
dirs = [dirname]
diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py
index 285c169..fee3a60 100644
--- a/Lib/test/test_glob.py
+++ b/Lib/test/test_glob.py
@@ -3,6 +3,7 @@ from test.test_support import run_unittest, TESTFN
import glob
import os
import shutil
+import sys
class GlobTests(unittest.TestCase):
@@ -110,6 +111,14 @@ class GlobTests(unittest.TestCase):
eq(self.glob('sym1'), [self.norm('sym1')])
eq(self.glob('sym2'), [self.norm('sym2')])
+ @unittest.skipUnless(sys.platform == "win32", "Win32 specific test")
+ def test_glob_magic_in_drive(self):
+ eq = self.assertSequencesEqual_noorder
+ eq(glob.glob('*:'), [])
+ eq(glob.glob(u'*:'), [])
+ eq(glob.glob('?:'), [])
+ eq(glob.glob(u'?:'), [])
+
def test_main():
run_unittest(GlobTests)