Skip to content

Commit 7df543d

Browse files
committed
Merge pull request pallets#1703 from jeffwidman/master
Cleanup jsonify() function
2 parents 7b1ebfb + 0edf0a0 commit 7df543d

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

CHANGES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Version 1.0
1010

1111
- Added support to serializing top-level arrays to :func:`flask.jsonify`. This
1212
introduces a security risk in ancient browsers. See
13-
:ref:`json_security` for details.
13+
:ref:`json-security` for details.
1414
- Added before_render_template signal.
1515
- Added `**kwargs` to :meth:`flask.Test.test_client` to support passing
1616
additional keyword arguments to the constructor of

flask/json.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ def jsonify(*args, **kwargs):
211211
212212
1. Single argument: Passed straight through to :func:`dumps`.
213213
2. Multiple arguments: Converted to an array before being passed to
214-
:func:`dumps`.
214+
:func:`dumps`.
215215
3. Multiple keyword arguments: Converted to a dict before being passed to
216-
:func:`dumps`.
216+
:func:`dumps`.
217217
4. Both args and kwargs: Behavior undefined and will throw an exception.
218218
219219
Example usage::
@@ -237,7 +237,7 @@ def get_current_user():
237237
238238
.. versionchanged:: 1.0
239239
Added support for serializing top-level arrays. This introduces a
240-
security risk in ancient browsers. See :ref:`json_security` for details.
240+
security risk in ancient browsers. See :ref:`json-security` for details.
241241
242242
This function's response will be pretty printed if it was not requested
243243
with ``X-Requested-With: XMLHttpRequest`` to simplify debugging unless
@@ -260,12 +260,10 @@ def get_current_user():
260260
raise TypeError(
261261
"jsonify() behavior undefined when passed both args and kwargs"
262262
)
263-
elif len(args) == 1: # single args are passed directly to dumps()
263+
elif len(args) == 1: # single args are passed directly to dumps()
264264
data = args[0]
265-
elif args: # convert multiple args into an array
266-
data = list(args)
267-
else: # convert kwargs to a dict
268-
data = dict(kwargs)
265+
else:
266+
data = args or kwargs
269267

270268
# Note that we add '\n' to end of response
271269
# (see https://github.com/mitsuhiko/flask/pull/1262)

0 commit comments

Comments
 (0)