Merge remote-tracking branch 'origin/1.0-maintenance'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parents 4f32c6d, ded7cbe · Browse files · 5 files·+39 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+39 added−4 removed
- tests:+8 added−2 removed
- other:+31 added−2 removed
Provenance
- Commit
a74864e- Tree
c7d9e49- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
4f32c6d- Parent 2
ded7cbe
5 files changed+39 added−4 removed
modified:flask/app.py+18 added-1 removed
18 unmodified lines19 20 from werkzeug.datastructures import Headers, ImmutableDict21 from werkzeug.exceptions import BadRequest, BadRequestKeyError, HTTPException, \22 InternalServerError, MethodNotAllowed, default_exceptions23-from werkzeug.routing import BuildError, Map, RequestRedirect, Rule23+from werkzeug.routing import BuildError, Map, RequestRedirect, \24+ RoutingException, Rule25 26 from . import cli, json27 from ._compat import integer_types, reraise, string_types, text_type28 from .config import Config, ConfigAttribute1602 unmodified lines1631 """Handles an HTTP exception. By default this will invoke the1632 registered error handlers and fall back to returning the1633 exception as response.1634 1635+ .. versionchanged:: 1.0.31636+ ``RoutingException``, used internally for actions such as1637+ slash redirects during routing, is not passed to error1638+ handlers.1639+1640+ .. 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``.1644+1645 .. 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 e1651 1652+ # 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 e1657+1658 handler = self._find_error_handler(e)1659 if handler is None:1660 return e1661 return handler(e)672 unmodified linesmodified:flask/helpers.py+3 added
575 unmodified lines576 if attachment_filename is None:577 raise TypeError('filename unavailable, required for '578 'sending as attachment')579 580+ if not isinstance(attachment_filename, text_type):581+ attachment_filename = attachment_filename.decode('utf-8')582+583 try:584 attachment_filename = attachment_filename.encode('ascii')585 except UnicodeEncodeError:586 filenames = {484 unmodified linesmodified:tests/test_helpers.py+2 added
678 unmodified lines679 ('index.html', 'index.html', False),680 (u'Ñandú/pingüino.txt', '"Nandu/pinguino.txt"',681 '%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt'),682 (u'Vögel.txt', 'Vogel.txt', 'V%C3%B6gel.txt'),683+ # Native string not marked as Unicode on Python 2684+ ('tést.txt', 'test.txt', 't%C3%A9st.txt'),685 ))686 def test_attachment_filename_encoding(self, filename, ascii, utf8):687 rv = flask.send_file('static/index.html', as_attachment=True, attachment_filename=filename)688 rv.close()318 unmodified linesmodified:tests/test_user_error_handler.py+6 added-2 removed
182 unmodified lines183 @app.route('/forbidden')184 def forbidden():185 raise Forbidden()186 187+ @app.route("/slash/")188+ def slash():189+ return "slash"190+191 app.register_blueprint(bp, url_prefix='/bp')192 193 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'194-195-198+ # Don't handle RequestRedirect raised when adding slash.199+ assert c.get("/slash", follow_redirects=True).data == b"slash"modified:CHANGES.rst+10 added-1 removed
34 unmodified lines35 - :func:`send_file` encodes filenames as ASCII instead of Latin-136 (ISO-8859-1). This fixes compatibility with Gunicorn, which is37 stricter about header encodings than PEP 3333. (`#2766`_)38 - Allow custom CLIs using ``FlaskGroup`` to set the debug flag without39- it always being overwritten based on environment variables. (`#2765`_)39+ it always being overwritten based on environment variables.40+ (`#2765`_)41 - ``flask --version`` outputs Werkzeug's version and simplifies the42 Python version. (`#2825`_)43+- :func:`send_file` handles an ``attachment_filename`` that is a44+ native Python 2 string (bytes) with UTF-8 coded bytes. (`#2933`_)45+- A catch-all error handler registered for ``HTTPException`` will not46+ handle ``RoutingExcpetion``, which is used internally during47+ routing. This fixes the unexpected behavior that had been introduced48+ in 1.0. (`#2986`_)49 50 .. _#2766: https://github.com/pallets/flask/issues/276651 .. _#2765: https://github.com/pallets/flask/pull/276552 .. _#2825: https://github.com/pallets/flask/pull/282553+.. _#2933: https://github.com/pallets/flask/issues/293354+.. _#2986: https://github.com/pallets/flask/pull/298655 56 57 Version 1.0.258 -------------911 unmodified lines