Skip to content

Commit e738962

Browse files
[3.8] bpo-41043: Escape literal part of the path for glob(). (pythonGH-20994). (pythonGH-21277)
(cherry picked from commit 9355868)
1 parent cbdacb9 commit e738962

File tree

22 files changed

+31
-27
lines changed

22 files changed

+31
-27
lines changed

Lib/distutils/command/build_py.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import importlib.util
77
import sys
8-
from glob import glob
8+
import glob
99

1010
from distutils.core import Command
1111
from distutils.errors import *
@@ -125,7 +125,7 @@ def find_data_files(self, package, src_dir):
125125
files = []
126126
for pattern in globs:
127127
# Each pattern has to be converted to a platform-specific path
128-
filelist = glob(os.path.join(src_dir, convert_path(pattern)))
128+
filelist = glob.glob(os.path.join(glob.escape(src_dir), convert_path(pattern)))
129129
# Files that match more than one pattern are only added once
130130
files.extend([fn for fn in filelist if fn not in files
131131
and os.path.isfile(fn)])
@@ -216,7 +216,7 @@ def check_module(self, module, module_file):
216216

217217
def find_package_modules(self, package, package_dir):
218218
self.check_package(package, package_dir)
219-
module_files = glob(os.path.join(package_dir, "*.py"))
219+
module_files = glob.glob(os.path.join(glob.escape(package_dir), "*.py"))
220220
modules = []
221221
setup_script = os.path.abspath(self.distribution.script_name)
222222

Lib/idlelib/tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def listicons(icondir=ICONDIR):
3838
"""Utility to display the available icons."""
3939
root = Tk()
4040
import glob
41-
list = glob.glob(os.path.join(icondir, "*.gif"))
41+
list = glob.glob(os.path.join(glob.escape(icondir), "*.gif"))
4242
list.sort()
4343
images = []
4444
row = column = 0

Lib/imghdr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def testall(list, recursive, toplevel):
152152
if recursive or toplevel:
153153
print('recursing down:')
154154
import glob
155-
names = glob.glob(os.path.join(filename, '*'))
155+
names = glob.glob(os.path.join(glob.escape(filename), '*'))
156156
testall(names, recursive, 0)
157157
else:
158158
print('*** directory (use -r) ***')

Lib/pdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ def _complete_location(self, text, line, begidx, endidx):
474474
except Exception:
475475
ret = []
476476
# Then, try to complete file names as well.
477-
globs = glob.glob(text + '*')
477+
globs = glob.glob(glob.escape(text) + '*')
478478
for fn in globs:
479479
if os.path.isdir(fn):
480480
ret.append(fn + '/')

Lib/sndhdr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def testall(list, recursive, toplevel):
241241
if recursive or toplevel:
242242
print('recursing down:')
243243
import glob
244-
names = glob.glob(os.path.join(filename, '*'))
244+
names = glob.glob(os.path.join(glob.escape(filename), '*'))
245245
testall(names, recursive, 0)
246246
else:
247247
print('*** directory (use -r) ***')

Lib/test/_test_multiprocessing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4222,7 +4222,7 @@ class _TestImportStar(unittest.TestCase):
42224222
def get_module_names(self):
42234223
import glob
42244224
folder = os.path.dirname(multiprocessing.__file__)
4225-
pattern = os.path.join(folder, '*.py')
4225+
pattern = os.path.join(glob.escape(folder), '*.py')
42264226
files = glob.glob(pattern)
42274227
modules = [os.path.splitext(os.path.split(f)[1])[0] for f in files]
42284228
modules = ['multiprocessing.' + m for m in modules]

Lib/test/libregrtest/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def create_temp_dir(self):
602602
def cleanup(self):
603603
import glob
604604

605-
path = os.path.join(self.tmp_dir, 'test_python_*')
605+
path = os.path.join(glob.escape(self.tmp_dir), 'test_python_*')
606606
print("Cleanup %s directory" % self.tmp_dir)
607607
for name in glob.glob(path):
608608
if os.path.isdir(name):

Lib/test/support/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2625,7 +2625,7 @@ def _platform_specific(self):
26252625
dll,
26262626
os.path.join(dest_dir, os.path.basename(dll))
26272627
))
2628-
for runtime in glob.glob(os.path.join(src_dir, "vcruntime*.dll")):
2628+
for runtime in glob.glob(os.path.join(glob.escape(src_dir), "vcruntime*.dll")):
26292629
self._also_link.append((
26302630
runtime,
26312631
os.path.join(dest_dir, os.path.basename(runtime))

Lib/test/test_bz2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class BaseTest(unittest.TestCase):
6969
# simply use the bigger test data for all tests.
7070
test_size = 0
7171
BIG_TEXT = bytearray(128*1024)
72-
for fname in glob.glob(os.path.join(os.path.dirname(__file__), '*.py')):
72+
for fname in glob.glob(os.path.join(glob.escape(os.path.dirname(__file__)), '*.py')):
7373
with open(fname, 'rb') as fh:
7474
test_size += fh.readinto(memoryview(BIG_TEXT)[test_size:])
7575
if test_size > 128*1024:

Lib/test/test_crashers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from test.support.script_helper import assert_python_failure
1212

1313
CRASHER_DIR = os.path.join(os.path.dirname(__file__), "crashers")
14-
CRASHER_FILES = os.path.join(CRASHER_DIR, "*.py")
14+
CRASHER_FILES = os.path.join(glob.escape(CRASHER_DIR), "*.py")
1515

1616
infinite_loops = ["infinite_loop_re.py", "nasty_eq_vs_dict.py"]
1717

0 commit comments

Comments
 (0)