Skip to content

Commit

Permalink
Remove JSONIFY_END_WITH_NEWLINE config var
Browse files Browse the repository at this point in the history
Now JSON responses are always terminated with a newline

per @untitaker's
[comment](#1262 (comment))
  • Loading branch information
msabramo committed Dec 6, 2014
1 parent 843cd67 commit 9722530
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down
8 changes: 2 additions & 6 deletions flask/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
17 changes: 2 additions & 15 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"
Expand All @@ -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 =\
Expand Down

0 comments on commit 9722530

Please sign in to comment.