diff --git a/CHANGES b/CHANGES index 92bfcf3094..443bdac81a 100644 --- a/CHANGES +++ b/CHANGES @@ -53,7 +53,7 @@ Version 1.0 - Add "pretty" and "compressed" separators definitions in jsonify() method. Reduces JSON response size when JSONIFY_PRETTYPRINT_REGULAR=False by removing unnecessary white space included by default after separators. -- Added the ``JSONIFY_END_WITH_NEWLINE`` configuration variable. +- JSON responses are now terminated with a newline character. Version 0.10.2 diff --git a/docs/config.rst b/docs/config.rst index fb2db5077e..fb39b4c4a6 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -182,9 +182,6 @@ The following configuration values are used internally by Flask: if they are not requested by an XMLHttpRequest object (controlled by the ``X-Requested-With`` header) -``JSONIFY_END_WITH_NEWLINE`` If this is set to ``True``, ``jsonify`` - responses will be terminated with a newline - character. ``TEMPLATES_AUTO_RELOAD`` Whether to check for modifications of the template source and reload it automatically. By default the value is diff --git a/flask/app.py b/flask/app.py index c23d207078..7532b99091 100644 --- a/flask/app.py +++ b/flask/app.py @@ -297,7 +297,6 @@ def _set_request_globals_class(self, value): 'JSON_AS_ASCII': True, 'JSON_SORT_KEYS': True, 'JSONIFY_PRETTYPRINT_REGULAR': True, - 'JSONIFY_END_WITH_NEWLINE': False, 'TEMPLATES_AUTO_RELOAD': None, }) diff --git a/flask/json.py b/flask/json.py index 036a89ad30..0e9d9ef2ed 100644 --- a/flask/json.py +++ b/flask/json.py @@ -232,9 +232,6 @@ def get_current_user(): spaces after separators. .. versionadded:: 0.2 - - To ensure that the output is terminated with a newline, set the - ``JSONIFY_END_WITH_NEWLINE`` config parameter. """ indent = None @@ -248,9 +245,8 @@ def get_current_user(): rv = current_app.response_class( dumps(dict(*args, **kwargs), indent=indent, separators=separators), mimetype='application/json') - if current_app.config['JSONIFY_END_WITH_NEWLINE']: - if not rv.data.endswith(b'\n'): - rv.data += b'\n' + if not rv.data.endswith(b'\n'): + rv.data += b'\n' return rv diff --git a/tests/test_basic.py b/tests/test_basic.py index 87cf713cca..e214aee79b 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -942,7 +942,7 @@ def test_make_response_with_response_instance(): rv = flask.make_response( flask.jsonify({'msg': 'W00t'}), 400) assert rv.status_code == 400 - assert rv.data == b'{\n "msg": "W00t"\n}' + assert rv.data == b'{\n "msg": "W00t"\n}\n' assert rv.mimetype == 'application/json' rv = flask.make_response( @@ -963,7 +963,7 @@ def test_jsonify_no_prettyprint(): app = flask.Flask(__name__) app.config.update({"JSONIFY_PRETTYPRINT_REGULAR": False}) with app.test_request_context(): - compressed_msg = b'{"msg":{"submsg":"W00t"},"msg2":"foobar"}' + compressed_msg = b'{"msg":{"submsg":"W00t"},"msg2":"foobar"}\n' uncompressed_msg = { "msg": { "submsg": "W00t" @@ -979,19 +979,6 @@ def test_jsonify_no_prettyprint(): def test_jsonify_prettyprint(): app = flask.Flask(__name__) app.config.update({"JSONIFY_PRETTYPRINT_REGULAR": True}) - with app.test_request_context(): - compressed_msg = {"msg":{"submsg":"W00t"},"msg2":"foobar"} - pretty_response =\ - b'{\n "msg": {\n "submsg": "W00t"\n }, \n "msg2": "foobar"\n}' - - rv = flask.make_response( - flask.jsonify(compressed_msg), 200) - assert rv.data == pretty_response - - -def test_jsonify_end_with_newline(): - app = flask.Flask(__name__) - app.config.update({"JSONIFY_END_WITH_NEWLINE": True}) with app.test_request_context(): compressed_msg = {"msg":{"submsg":"W00t"},"msg2":"foobar"} pretty_response =\