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.
This commit is contained in:
Antoine Pitrou 2012-12-16 13:50:19 +01:00
commit 3c331bb729
3 changed files with 21 additions and 1 deletions

View File

@ -29,7 +29,10 @@ def iglob(pathname):
for name in glob1(None, 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]

View File

@ -4,6 +4,7 @@ from test.support import (run_unittest, TESTFN, skip_unless_symlink,
import glob
import os
import shutil
import sys
class GlobTests(unittest.TestCase):
@ -110,6 +111,18 @@ 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(b'*:'), [])
eq(glob.glob('?:'), [])
eq(glob.glob(b'?:'), [])
eq(glob.glob('\\\\?\\c:\\'), ['\\\\?\\c:\\'])
eq(glob.glob(b'\\\\?\\c:\\'), [b'\\\\?\\c:\\'])
eq(glob.glob('\\\\*\\*\\'), [])
eq(glob.glob(b'\\\\*\\*\\'), [])
def test_main():
run_unittest(GlobTests)

View File

@ -108,6 +108,10 @@ Core and Builtins
Library
-------
- 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.
- Issue #15783: Except for the number methods, the C version of decimal now
supports all None default values present in decimal.py. These values were
largely undocumented.