File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,7 +28,10 @@ def iglob(pathname):
2828 if not dirname :
2929 yield from glob1 (None , basename )
3030 return
31- if has_magic (dirname ):
31+ # `os.path.split()` returns the argument itself as a dirname if it is a
32+ # drive or UNC path. Prevent an infinite recursion if a drive or UNC path
33+ # contains magic characters (i.e. r'\\?\C:').
34+ if dirname != pathname and has_magic (dirname ):
3235 dirs = iglob (dirname )
3336 else :
3437 dirs = [dirname ]
Original file line number Diff line number Diff line change 44import glob
55import os
66import shutil
7+ import sys
78
89
910class GlobTests (unittest .TestCase ):
@@ -110,6 +111,18 @@ def test_glob_broken_symlinks(self):
110111 eq (self .glob ('sym1' ), [self .norm ('sym1' )])
111112 eq (self .glob ('sym2' ), [self .norm ('sym2' )])
112113
114+ @unittest .skipUnless (sys .platform == "win32" , "Win32 specific test" )
115+ def test_glob_magic_in_drive (self ):
116+ eq = self .assertSequencesEqual_noorder
117+ eq (glob .glob ('*:' ), [])
118+ eq (glob .glob (b'*:' ), [])
119+ eq (glob .glob ('?:' ), [])
120+ eq (glob .glob (b'?:' ), [])
121+ eq (glob .glob ('\\ \\ ?\\ c:\\ ' ), ['\\ \\ ?\\ c:\\ ' ])
122+ eq (glob .glob (b'\\ \\ ?\\ c:\\ ' ), [b'\\ \\ ?\\ c:\\ ' ])
123+ eq (glob .glob ('\\ \\ *\\ *\\ ' ), [])
124+ eq (glob .glob (b'\\ \\ *\\ *\\ ' ), [])
125+
113126
114127def test_main ():
115128 run_unittest (GlobTests )
Original file line number Diff line number Diff line change @@ -167,6 +167,10 @@ Core and Builtins
167167Library
168168-------
169169
170+ - Issue #16626: Fix infinite recursion in glob.glob() on Windows when the
171+ pattern contains a wildcard in the drive or UNC path. Patch by Serhiy
172+ Storchaka.
173+
170174- Issue #15783: Except for the number methods, the C version of decimal now
171175 supports all None default values present in decimal.py. These values were
172176 largely undocumented.
You can’t perform that action at this time.
0 commit comments