Permalink
Browse files

* jsonify now properly sets charset to utf-8.

--HG--
branch : trunk
  • Loading branch information...
1 parent d499bf1 commit b5bf0c6e495530e8f8d9d16a867f0023d5b4c307 @bbangert bbangert committed Dec 18, 2010
Showing with 4 additions and 2 deletions.
  1. +1 −0 CHANGELOG
  2. +2 −2 pylons/decorators/__init__.py
  3. +1 −0 tests/test_units/test_decorator_jsonify.py
View
@@ -2,6 +2,7 @@ Pylons Changelog
================
1.1 (**tip**)
+* jsonify now properly sets charset to utf-8.
* Add ability for jsonify to handle objects with a __json__ attribute using
custom JSONEncoder class similar to TG2. Patch by Bob Farrell.
* Added ability for __before__ to reference a callable function. Patch
@@ -41,7 +41,7 @@ def jsonify(func, *args, **kwargs):
"""
pylons = get_pylons(args)
- pylons.response.headers['Content-Type'] = 'application/json'
+ pylons.response.headers['Content-Type'] = 'application/json; charset=utf-8'
data = func(*args, **kwargs)
if isinstance(data, (list, tuple)):
msg = "JSON responses with Array envelopes are susceptible to " \
@@ -50,7 +50,7 @@ def jsonify(func, *args, **kwargs):
warnings.warn(msg, Warning, 2)
log.warning(msg)
log.debug("Returning JSON wrapped action output")
- return simplejson.dumps(data, cls=JSONEncoder)
+ return simplejson.dumps(data, cls=JSONEncoder, encoding='utf-8')
def validate(schema=None, validators=None, form=None, variable_decode=False,
@@ -52,3 +52,4 @@ def test_bad_json(self):
def test_good_json(self):
response = self.get_response(action='test_good_json')
assert '{"fred": 42}' in response
+ assert response.header('Content-Type') == 'application/json; charset=utf-8'

0 comments on commit b5bf0c6

Please sign in to comment.