diff --git a/SOURCES/0001-detect-UTF-encodings-when-loading-json.patch b/SOURCES/0001-detect-UTF-encodings-when-loading-json.patch deleted file mode 100644 index 67b925a..0000000 --- a/SOURCES/0001-detect-UTF-encodings-when-loading-json.patch +++ /dev/null @@ -1,167 +0,0 @@ -From 50062c4d8c4108d17b7f12d9518ce883956d3921 Mon Sep 17 00:00:00 2001 -From: David Lord -Date: Tue, 10 Apr 2018 09:29:48 -0700 -Subject: [PATCH] detect UTF encodings when loading json - -(cherry picked from commit 0e1e9a04aaf29ab78f721cfc79ac2a691f6e3929) ---- - flask/json.py | 49 ++++++++++++++++++++++++++++++++++++++++++- - flask/wrappers.py | 13 +++--------- - tests/test_helpers.py | 28 ++++++++++++++----------- - 3 files changed, 67 insertions(+), 23 deletions(-) - -diff --git a/flask/json.py b/flask/json.py -index 16e0c29..114873e 100644 ---- a/flask/json.py -+++ b/flask/json.py -@@ -8,6 +8,7 @@ - :copyright: (c) 2015 by Armin Ronacher. - :license: BSD, see LICENSE for more details. - """ -+import codecs - import io - import uuid - from datetime import date -@@ -108,6 +109,49 @@ def _load_arg_defaults(kwargs): - kwargs.setdefault('cls', JSONDecoder) - - -+def detect_encoding(data): -+ """Detect which UTF codec was used to encode the given bytes. -+ -+ The latest JSON standard (:rfc:`8259`) suggests that only UTF-8 is -+ accepted. Older documents allowed 8, 16, or 32. 16 and 32 can be big -+ or little endian. Some editors or libraries may prepend a BOM. -+ -+ :param data: Bytes in unknown UTF encoding. -+ :return: UTF encoding name -+ """ -+ head = data[:4] -+ -+ if head[:3] == codecs.BOM_UTF8: -+ return 'utf-8-sig' -+ -+ if b'\x00' not in head: -+ return 'utf-8' -+ -+ if head in (codecs.BOM_UTF32_BE, codecs.BOM_UTF32_LE): -+ return 'utf-32' -+ -+ if head[:2] in (codecs.BOM_UTF16_BE, codecs.BOM_UTF16_LE): -+ return 'utf-16' -+ -+ if len(head) == 4: -+ if head[:3] == b'\x00\x00\x00': -+ return 'utf-32-be' -+ -+ if head[::2] == b'\x00\x00': -+ return 'utf-16-be' -+ -+ if head[1:] == b'\x00\x00\x00': -+ return 'utf-32-le' -+ -+ if head[1::2] == b'\x00\x00': -+ return 'utf-16-le' -+ -+ if len(head) == 2: -+ return 'utf-16-be' if head.startswith(b'\x00') else 'utf-16-le' -+ -+ return 'utf-8' -+ -+ - def dumps(obj, **kwargs): - """Serialize ``obj`` to a JSON formatted ``str`` by using the application's - configured encoder (:attr:`~flask.Flask.json_encoder`) if there is an -@@ -142,7 +186,10 @@ def loads(s, **kwargs): - """ - _load_arg_defaults(kwargs) - if isinstance(s, bytes): -- s = s.decode(kwargs.pop('encoding', None) or 'utf-8') -+ encoding = kwargs.pop('encoding', None) -+ if encoding is None: -+ encoding = detect_encoding(s) -+ s = s.decode(encoding) - return _json.loads(s, **kwargs) - - -diff --git a/flask/wrappers.py b/flask/wrappers.py -index 04bdcb5..3e600fc 100644 ---- a/flask/wrappers.py -+++ b/flask/wrappers.py -@@ -144,17 +144,10 @@ class Request(RequestBase): - if not (force or self.is_json): - return None - -- # We accept a request charset against the specification as -- # certain clients have been using this in the past. This -- # fits our general approach of being nice in what we accept -- # and strict in what we send out. -- request_charset = self.mimetype_params.get('charset') -+ data = _get_data(self, cache) -+ - try: -- data = _get_data(self, cache) -- if request_charset is not None: -- rv = json.loads(data, encoding=request_charset) -- else: -- rv = json.loads(data) -+ rv = json.loads(data) - except ValueError as e: - if silent: - rv = None -diff --git a/tests/test_helpers.py b/tests/test_helpers.py -index 9320ef7..9990782 100644 ---- a/tests/test_helpers.py -+++ b/tests/test_helpers.py -@@ -21,6 +21,8 @@ from werkzeug.datastructures import Range - from werkzeug.exceptions import BadRequest, NotFound - from werkzeug.http import parse_cache_control_header, parse_options_header - from werkzeug.http import http_date -+ -+from flask import json - from flask._compat import StringIO, text_type - - -@@ -34,6 +36,20 @@ def has_encoding(name): - - - class TestJSON(object): -+ @pytest.mark.parametrize('value', ( -+ 1, 't', True, False, None, -+ [], [1, 2, 3], -+ {}, {'foo': u'🐍'}, -+ )) -+ @pytest.mark.parametrize('encoding', ( -+ 'utf-8', 'utf-8-sig', -+ 'utf-16-le', 'utf-16-be', 'utf-16', -+ 'utf-32-le', 'utf-32-be', 'utf-32', -+ )) -+ def test_detect_encoding(self, value, encoding): -+ data = json.dumps(value).encode(encoding) -+ assert json.detect_encoding(data) == encoding -+ assert json.loads(data) == value - - def test_ignore_cached_json(self): - app = flask.Flask(__name__) -@@ -85,18 +101,6 @@ class TestJSON(object): - rv = c.post('/json', data='"foo"', content_type='application/x+json') - assert rv.data == b'foo' - -- def test_json_body_encoding(self): -- app = flask.Flask(__name__) -- app.testing = True -- @app.route('/') -- def index(): -- return flask.request.get_json() -- -- c = app.test_client() -- resp = c.get('/', data=u'"Hällo Wörld"'.encode('iso-8859-15'), -- content_type='application/json; charset=iso-8859-15') -- assert resp.data == u'Hällo Wörld'.encode('utf-8') -- - def test_json_as_unicode(self): - app = flask.Flask(__name__) - --- -2.17.1 - diff --git a/SOURCES/0002-Fix-ValueError-for-some-invalid-Range-requests.patch b/SOURCES/0002-Fix-ValueError-for-some-invalid-Range-requests.patch deleted file mode 100644 index 3ffd4c2..0000000 --- a/SOURCES/0002-Fix-ValueError-for-some-invalid-Range-requests.patch +++ /dev/null @@ -1,87 +0,0 @@ -From c52e1b7388c17466a551391cdf81964bf0b7aef0 Mon Sep 17 00:00:00 2001 -From: ThiefMaster -Date: Thu, 23 Nov 2017 10:32:13 +0100 -Subject: [PATCH 2/3] Fix ValueError for some invalid Range requests - -fixes #2526 ---- - CHANGES | 8 ++++++++ - flask/helpers.py | 3 ++- - tests/test_helpers.py | 21 ++++++++++++++++++++- - 3 files changed, 30 insertions(+), 2 deletions(-) - -diff --git a/CHANGES b/CHANGES -index 3456276a..b32b98cb 100644 ---- a/CHANGES -+++ b/CHANGES -@@ -15,6 +15,14 @@ Major release, unreleased - method returns compressed response by default, and pretty response in - debug mode. - -+Version 0.12.3 -+-------------- -+ -+Bugfix release, unreleased -+ -+- Fix a ValueError caused by invalid Range requests in some cases -+ -+ - Version 0.12.2 - -------------- - -diff --git a/flask/helpers.py b/flask/helpers.py -index 4bb1d1c9..caaad9a3 100644 ---- a/flask/helpers.py -+++ b/flask/helpers.py -@@ -591,7 +591,8 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False, - rv = rv.make_conditional(request, accept_ranges=True, - complete_length=fsize) - except RequestedRangeNotSatisfiable: -- file.close() -+ if file is not None: -+ file.close() - raise - else: - rv = rv.make_conditional(request) -diff --git a/tests/test_helpers.py b/tests/test_helpers.py -index 9320ef71..69350751 100644 ---- a/tests/test_helpers.py -+++ b/tests/test_helpers.py -@@ -468,7 +468,7 @@ class TestSendfile(object): - - @pytest.mark.skipif( - not callable(getattr(Range, 'to_content_range_header', None)), -- reason="not implement within werkzeug" -+ reason="not implemented within werkzeug" - ) - def test_send_file_range_request(self): - app = flask.Flask(__name__) -@@ -529,6 +529,25 @@ class TestSendfile(object): - assert rv.status_code == 200 - rv.close() - -+ @pytest.mark.skipif( -+ not callable(getattr(Range, 'to_content_range_header', None)), -+ reason="not implemented within werkzeug" -+ ) -+ def test_send_file_range_request_xsendfile_invalid(self): -+ # https://github.com/pallets/flask/issues/2526 -+ app = flask.Flask(__name__) -+ app.use_x_sendfile = True -+ -+ @app.route('/') -+ def index(): -+ return flask.send_file('static/index.html', conditional=True) -+ -+ c = app.test_client() -+ -+ rv = c.get('/', headers={'Range': 'bytes=1000-'}) -+ assert rv.status_code == 416 -+ rv.close() -+ - def test_attachment(self): - app = flask.Flask(__name__) - with app.test_request_context(): --- -2.21.0 - diff --git a/SOURCES/0003-be-smarter-about-adding-.cli-to-reloader-command.patch b/SOURCES/0003-be-smarter-about-adding-.cli-to-reloader-command.patch deleted file mode 100644 index 4b9f293..0000000 --- a/SOURCES/0003-be-smarter-about-adding-.cli-to-reloader-command.patch +++ /dev/null @@ -1,47 +0,0 @@ -From 18c9db47940c1195809a0c82fcb85601c3f4df46 Mon Sep 17 00:00:00 2001 -From: David Lord -Date: Sun, 4 Jun 2017 12:26:21 -0700 -Subject: [PATCH 3/3] be smarter about adding ".cli" to reloader command python - -m flask.cli raises an import warning on > 2.6 it's only needed on 2.6, - "flask" works otherwise - ---- - flask/cli.py | 18 +++++++++--------- - 1 file changed, 9 insertions(+), 9 deletions(-) - -diff --git a/flask/cli.py b/flask/cli.py -index 074ee768..ca455671 100644 ---- a/flask/cli.py -+++ b/flask/cli.py -@@ -494,19 +494,19 @@ Example usage: - - - def main(as_module=False): -- this_module = __package__ + '.cli' - args = sys.argv[1:] - - if as_module: -- if sys.version_info >= (2, 7): -- name = 'python -m ' + this_module.rsplit('.', 1)[0] -- else: -- name = 'python -m ' + this_module -+ this_module = 'flask' -+ -+ if sys.version_info < (2, 7): -+ this_module += '.cli' -+ -+ name = 'python -m ' + this_module - -- # This module is always executed as "python -m flask.run" and as such -- # we need to ensure that we restore the actual command line so that -- # the reloader can properly operate. -- sys.argv = ['-m', this_module] + sys.argv[1:] -+ # Python rewrites "python -m flask" to the path to the file in argv. -+ # Restore the original command so that the reloader works. -+ sys.argv = ['-m', this_module] + args - else: - name = None - --- -2.21.0 -