Hi,
I was facing an issue when using incorrect variable name in Flask template. An dash "-" linked variable name in template cause Flask to hang without throwing any exception.
At first I doubt it's Jinja issue but I found Jinja raised the exception and Werkzeug handled it.
Eventually, I found an endless loop in Python\Lib\traceback.py to walk trackback stacks. The
trackbacks are stored in a link which nodes point to next. In flask\templating.py,
flask\app.py and werkzeug\debug\tbtools.py, the exception was catched. In
handle_exception() of flask\app.py, Werkzeug wants to log it and print it out.
The trackback link has looped reference as below picture.

Hope its helpful. Thanks you.
Expected Behavior
Render variable out or throw exception out.
import sys
from flask import Flask, request, render_template_string, make_response, url_for, redirect
### {{ font-size }} causes app hang ###
app = Flask(__name__)
template_page = '''
<html>
<head>
<meta charset="{{ encoding }}" />
<meta http-equiv="content-type" content="text/html; charset={{ encoding }}" />
<style type="text/css">
body, pre, p, div, input, h1,h2,h3,h4,h5 {
font-family : Consolas, Courier New;
}
</style>
</head>
<body>
<div id="wrapper" style="font-size:{{ font-size }}em">
{{ content | safe }}
</div>
</body>'''
@app.route('/', methods=['GET'])
def index():
context = {
"encoding": 'utf-8',
"font-size": 0.9,
"content": 'hello flask'
}
resp = make_response(render_template_string(template_page, **context))
resp.headers['Content-Type'] = 'text/html; charset=utf-8'
return resp
if __name__ == "__main__":
# app.run(debug=True, host='0.0.0.0', port=8080)
app.run()
Actual Behavior
App hangs.
Environment
- Python version: 3.6.8
- Flask version: 1.1.1
- Werkzeug version: 0.16.1
Hi,
I was facing an issue when using incorrect variable name in
Flasktemplate. An dash "-" linked variable name in template cause Flask to hang without throwing any exception.At first I doubt it's
Jinjaissue but I found Jinja raised the exception andWerkzeughandled it.Eventually, I found an endless loop in
Python\Lib\traceback.pyto walk trackback stacks. Thetrackbacks are stored in a link which nodes point to next. In
flask\templating.py,flask\app.pyandwerkzeug\debug\tbtools.py, the exception was catched. Inhandle_exception()offlask\app.py,Werkzeugwants to log it and print it out.The trackback link has looped reference as below picture.
Hope its helpful. Thanks you.
Expected Behavior
Render variable out or throw exception out.
Actual Behavior
App hangs.
Environment