Skip to content
Myr

Merge pull request #2994 from jarek/werkzeug-640-exceptions-during-bind

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Handle errors during create_url_adapter

authored by David Lord · committed by GitHub · parents 3394191, a5709e7 · Browse files · 3 files+65 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+65 added−2 removed

  • tests:+54 added−0 removed
  • other:+11 added−2 removed

3 files+65 added−2 removed

modified:flask/ctx.py+7 added-2 removed
280 unmodified lines
281 self.app = app282 if request is None:283 request = app.request_class(environ)284 self.request = request285 self.url_adapter = None286 try:285 self.url_adapter = app.create_url_adapter(self.request)287 self.url_adapter = app.create_url_adapter(self.request)288 except HTTPException as e:289 self.request.routing_exception = e290 self.flashes = None291 self.session = session292293 # Request contexts can be pushed multiple times and interleaved with
14 unmodified lines
308 # object. These will be called before the regular "after_request"309 # functions.310 self._after_request_functions = []311312 if self.url_adapter is not None:308 self.match_request()313 self.match_request()314315 def _get_g(self):316 return _app_ctx_stack.top.g317 def _set_g(self, value):
151 unmodified lines
modified:tests/test_reqctx.py+54 added
227 unmodified lines
228 response = app.test_client().get('/')229 assert response.status_code == 500230 assert not flask.request231 assert not flask.current_app232233234def test_bad_environ_raises_bad_request():235 app = flask.Flask(__name__)236237 # We cannot use app.test_client() for the Unicode-rich Host header,238 # because werkzeug enforces latin1 on Python 2.239 # However it works when actually passed to the server.240241 from flask.testing import make_test_environ_builder242 builder = make_test_environ_builder(app)243 environ = builder.get_environ()244245 # use a non-printable character in the Host - this is key to this test246 environ['HTTP_HOST'] = u'\x8a'247248 with app.request_context(environ):249 response = app.full_dispatch_request()250 assert response.status_code == 400251252253def test_environ_for_valid_idna_completes():254 app = flask.Flask(__name__)255256 @app.route('/')257 def index():258 return 'Hello World!'259260 # We cannot use app.test_client() for the Unicode-rich Host header,261 # because werkzeug enforces latin1 on Python 2.262 # However it works when actually passed to the server.263264 from flask.testing import make_test_environ_builder265 builder = make_test_environ_builder(app)266 environ = builder.get_environ()267268 # these characters are all IDNA-compatible269 environ['HTTP_HOST'] = u'ąśźäüжŠßя.com'270271 with app.request_context(environ):272 response = app.full_dispatch_request()273274 assert response.status_code == 200275276277def test_normal_environ_completes():278 app = flask.Flask(__name__)279280 @app.route('/')281 def index():282 return 'Hello World!'283284 response = app.test_client().get('/', headers={'host': 'xn--on-0ia.com'})285 assert response.status_code == 200
modified:CHANGES.rst+4 added
10 unmodified lines
1112- :meth:`flask.RequestContext.copy` includes the current session13 object in the request context copy. This prevents ``flask.session`` 14 pointing to an out-of-date object. (`#2935`)15- Using built-in RequestContext, unprintable Unicode characters in Host16 header will result in a HTTP 400 response and not HTTP 500 as previously.17 (`#2994`)1819.. _#2935: https://github.com/pallets/flask/issues/293520.. _#2994: https://github.com/pallets/flask/pull/2994212223Version 1.0.324-------------
926 unmodified lines