New submission from Serhiy Storchaka <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue41043>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com