During the fuzzing of jinja2, I came across many SyntaxErrors that were raised during the call to _compile in environment.py. The source of these comes from the call to from_string, also in environment.py. I wanted to report this since it seems that syntax errors during compilation should be raised as a TemplateSyntaxError rather than just a SyntaxError. Below is an example of one of these exceptions. I would be happy to provide more context if this is something of interest to the developers.
from jinja2.environment import Environment
data = '''*{"
{{()------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Q-----------(true) }}
'''
env = Environment()
env.from_string(data)
File "rep.py", line 7, in <module>
env.from_string(data)
File "lib/python3.9/site-packages/jinja2/environment.py", line 1113, in from_string
return cls.from_code(self, self.compile(source), gs, None)
File "lib/python3.9/site-packages/jinja2/environment.py", line 771, in compile
return self._compile(source, filename)
File "lib/python3.9/site-packages/jinja2/environment.py", line 711, in _compile
return compile(source, filename, "exec")
File "<template>", line 13
yield str(((() - (-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(-(undefined(name='Q') if l_0_Q is missing else l_0_Q))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) - 1))
^
SyntaxError: too many nested parentheses
During the fuzzing of jinja2, I came across many SyntaxErrors that were raised during the call to
_compileinenvironment.py. The source of these comes from the call tofrom_string, also inenvironment.py. I wanted to report this since it seems that syntax errors during compilation should be raised as aTemplateSyntaxErrorrather than just aSyntaxError. Below is an example of one of these exceptions. I would be happy to provide more context if this is something of interest to the developers.Small Reproducer
Trace