New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Escape the literal part of the path for glob() #85215
Comments
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:
|
Would it be worth it to add a "base" keyword argument to glob.glob? |
It may be not exactly what you meant, but see bpo-38144. This issue actually was opened after I looked how that feature can be used in the stdlib and found that most of uses of glob() are vulnerable. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: