Possible python bug when using ~regex in file pattern
mitzkia opened this issue · comments
When I played with all-repos-find-files
found a python crash.
I have also reproduced with pure python so my feeling is that this is not all-repos
related, but I need help to validate this (can not decide).
Maybe the use-case is invalid?
Reproduction with all-repos-find-files
:
$ all-repos-find-files --output-paths '*'
Traceback (most recent call last):
File "/usr/local/bin/all-repos-find-files", line 10, in <module>
sys.exit(main())
File "/usr/local/lib/python3.6/dist-packages/all_repos/find_files.py", line 90, in main
output_paths=args.output_paths, use_color=args.color,
File "/usr/local/lib/python3.6/dist-packages/all_repos/find_files.py", line 60, in find_files_cli
repo_files = find_files(config, pattern)
File "/usr/local/lib/python3.6/dist-packages/all_repos/find_files.py", line 30, in find_files
regex = re.compile(pattern.encode())
File "/usr/lib/python3.6/re.py", line 233, in compile
return _compile(pattern, flags)
File "/usr/lib/python3.6/re.py", line 301, in _compile
p = sre_compile.compile(pattern, flags)
File "/usr/lib/python3.6/sre_compile.py", line 562, in compile
p = sre_parse.parse(p, flags)
File "/usr/lib/python3.6/sre_parse.py", line 855, in parse
p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
File "/usr/lib/python3.6/sre_parse.py", line 416, in _parse_sub
not nested and not items))
File "/usr/lib/python3.6/sre_parse.py", line 616, in _parse
source.tell() - here + len(this))
sre_constants.error: nothing to repeat at position 0
Reproduction with pure python:
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> "*".encode()
b'*'
>>> import re
>>> re.compile("*".encode())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/re.py", line 233, in compile
return _compile(pattern, flags)
File "/usr/lib/python3.6/re.py", line 301, in _compile
p = sre_compile.compile(pattern, flags)
File "/usr/lib/python3.6/sre_compile.py", line 562, in compile
p = sre_parse.parse(p, flags)
File "/usr/lib/python3.6/sre_parse.py", line 855, in parse
p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
File "/usr/lib/python3.6/sre_parse.py", line 416, in _parse_sub
not nested and not items))
File "/usr/lib/python3.6/sre_parse.py", line 616, in _parse
source.tell() - here + len(this))
sre_constants.error: nothing to repeat at position 0
*
is not a valid regex, to match all files, the simplest regex is ''
(the empty string) or more explicitly '.*'
Ok, I understand it, with '.*' it works correctly. In this case this is an invalid issue?
Should python handle this?
In this case this is an invalid issue?
correct!
ok, thx