Skip to content
Myr

Merge pull request #2986 from taion/do-not-handle-routing-exception

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

Do not handle RoutingExceptions with app error handlers

authored by David Lord · committed by GitHub · parents 38a3918, 662ce21 · Browse files · 3 files+29 added−3 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+29 added−3 removed

  • tests:+6 added−2 removed
  • other:+23 added−1 removed

3 files+29 added−3 removed

modified:flask/app.py+18 added-1 removed
18 unmodified lines
1920from werkzeug.datastructures import Headers, ImmutableDict21from werkzeug.exceptions import BadRequest, BadRequestKeyError, HTTPException, \22 InternalServerError, MethodNotAllowed, default_exceptions23from werkzeug.routing import BuildError, Map, RequestRedirect, Rule23from werkzeug.routing import BuildError, Map, RequestRedirect, \24 RoutingException, Rule2526from . import cli, json27from ._compat import integer_types, reraise, string_types, text_type28from .config import Config, ConfigAttribute
1602 unmodified lines
1631 """Handles an HTTP exception. By default this will invoke the1632 registered error handlers and fall back to returning the1633 exception as response.16341635 .. versionchanged:: 1.0.31636 ``RoutingException``, used internally for actions such as1637 slash redirects during routing, is not passed to error1638 handlers.16391640 .. versionchanged:: 1.01641 Exceptions are looked up by code *and* by MRO, so1642 ``HTTPExcpetion`` subclasses can be handled with a catch-all1643 handler for the base ``HTTPException``.16441645 .. versionadded:: 0.31646 """1647 # Proxy exceptions don't have error codes. We want to always return1648 # those unchanged as errors1649 if e.code is None:1650 return e16511652 # RoutingExceptions are used internally to trigger routing1653 # actions, such as slash redirects raising RequestRedirect. They1654 # are not raised or handled in user code.1655 if isinstance(e, RoutingException):1656 return e16571658 handler = self._find_error_handler(e)1659 if handler is None:1660 return e1661 return handler(e)
673 unmodified lines
modified:tests/test_user_error_handler.py+6 added-2 removed
182 unmodified lines
183 @app.route('/forbidden')184 def forbidden():185 raise Forbidden()186187 @app.route("/slash/")188 def slash():189 return "slash"190191 app.register_blueprint(bp, url_prefix='/bp')192193 c = app.test_client()194 assert c.get('/bp/undefined').data == b'bp-default'195 assert c.get('/bp/forbidden').data == b'bp-forbidden'196 assert c.get('/undefined').data == b'default'197 assert c.get('/forbidden').data == b'forbidden'194195198 # Don't handle RequestRedirect raised when adding slash.199 assert c.get("/slash", follow_redirects=True).data == b"slash"
modified:CHANGES.rst+5 added
17 unmodified lines
18- ``flask --version`` outputs Werkzeug's version and simplifies the19 Python version. (`#2825`_)20- :func:`send_file` handles an ``attachment_filename`` that is a21 native Python 2 string (bytes) with UTF-8 coded bytes. (`#2933`_)22- A catch-all error handler registered for ``HTTPException`` will not23 handle ``RoutingExcpetion``, which is used internally during24 routing. This fixes the unexpected behavior that had been introduced25 in 1.0. (`#2986`_)2627.. _#2766: https://github.com/pallets/flask/issues/276628.. _#2765: https://github.com/pallets/flask/pull/276529.. _#2825: https://github.com/pallets/flask/pull/282530.. _#2933: https://github.com/pallets/flask/issues/293331.. _#2986: https://github.com/pallets/flask/pull/2986323334Version 1.0.235-------------
896 unmodified lines