[New-bugs-announce] [issue41043] Escape the literal part of the path for glob()
Serhiy Storchaka
report at bugs.python.org
Fri Jun 19 17:16:43 EDT 2020
New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:
It is common to use glob() as
glob.glob(os.path.join(basedir, pattern))
But it does not work correctly if the base directory contains special globbing characters ('*', '?', '['). It is an uncommon case, so in most cases the code works. But when move sources to the directory containing special characters, built it and run tests, some tests will fail:
test test_tokenize failed -- Traceback (most recent call last):
File "/home/serhiy/py/[cpython]/Lib/test/test_tokenize.py", line 1615, in test_random_files
testfiles.remove(os.path.join(tempdir, "test_unicode_identifiers.py"))
ValueError: list.remove(x): x not in list
test test_multiprocessing_fork failed -- Traceback (most recent call last):
File "/home/serhiy/py/[cpython]/Lib/test/_test_multiprocessing.py", line 4272, in test_import
modules = self.get_module_names()
File "/home/serhiy/py/[cpython]/Lib/test/_test_multiprocessing.py", line 4267, in get_module_names
modules.remove('multiprocessing.__init__')
ValueError: list.remove(x): x not in list
test test_bz2 failed -- Traceback (most recent call last):
File "/home/serhiy/py/[cpython]/Lib/test/test_bz2.py", line 740, in testDecompressorChunksMaxsize
self.assertFalse(bzd.needs_input)
AssertionError: True is not false
test test_multiprocessing_forkserver failed -- Traceback (most recent call last):
File "/home/serhiy/py/[cpython]/Lib/test/_test_multiprocessing.py", line 4272, in test_import
modules = self.get_module_names()
File "/home/serhiy/py/[cpython]/Lib/test/_test_multiprocessing.py", line 4267, in get_module_names
modules.remove('multiprocessing.__init__')
ValueError: list.remove(x): x not in list
test test_multiprocessing_spawn failed -- Traceback (most recent call last):
File "/home/serhiy/py/[cpython]/Lib/test/_test_multiprocessing.py", line 4272, in test_import
modules = self.get_module_names()
File "/home/serhiy/py/[cpython]/Lib/test/_test_multiprocessing.py", line 4267, in get_module_names
modules.remove('multiprocessing.__init__')
ValueError: list.remove(x): x not in list
The proposed PR adds glob.escape() to the above code:
glob.glob(os.path.join(glob.escape(basedir), pattern))
----------
components: Library (Lib)
messages: 371903
nosy: serhiy.storchaka
priority: normal
severity: normal
status: open
title: Escape the literal part of the path for glob()
type: behavior
versions: Python 3.10, Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41043>
_______________________________________
More information about the New-bugs-announce
mailing list