Handle errors during create_url_adapter

If create_url_adapter raises (which it can if werkzeug cannot bind
environment, for example on non-ASCII Host header), we handle it as
other routing exceptions rather than raising through.

ref https://github.com/pallets/werkzeug/issues/640
This commit is contained in:
Jarek Piórkowski 2018-11-12 16:59:09 -05:00
parent 339419117f
commit ed9775fb77
2 changed files with 30 additions and 2 deletions

View file

@ -229,3 +229,26 @@ def test_session_error_pops_context():
assert response.status_code == 500
assert not flask.request
assert not flask.current_app
def test_bad_environ_raises_bad_request():
app = flask.Flask(__name__)
@app.route('/')
def index():
# shouldn't get here anyway
assert False
response = app.test_client().get('/', headers={'host': 'ąśź.com'})
assert response.status_code == 400
def test_normal_environ_completes():
app = flask.Flask(__name__)
@app.route('/')
def index():
return 'Hello World!'
response = app.test_client().get('/', headers={'host': 'xn--on-0ia.com'})
assert response.status_code == 200