Try to decode bytestrings from UTF8 in json_safe

Closes #148
This commit is contained in:
Kevin McCarthy
2014-07-06 10:27:17 -10:00
parent 320e994c30
commit 540b414490
2 changed files with 5 additions and 1 deletions
+1 -1
View File
@@ -77,6 +77,7 @@ def json_safe(string, content_type='application/octet-stream'):
URL scheme was chosen for its simplicity.
"""
try:
string = string.decode('utf-8')
_encoded = json.dumps(string)
return string
except (ValueError, TypeError):
@@ -152,7 +153,6 @@ def get_dict(*keys, **extras):
_keys = ('url', 'args', 'form', 'data', 'origin', 'headers', 'files', 'json')
assert all(map(_keys.__contains__, keys))
data = request.data
form = request.form
form = semiflatten(request.form)
+4
View File
@@ -47,6 +47,10 @@ class HttpbinTestCase(unittest.TestCase):
response = self.app.post('/post', data={"file": f.read()})
self.assertEqual(response.status_code, 200)
def test_post_body_unicode(self):
response = self.app.post('/post', data=u'оживлённым'.encode('utf-8'))
self.assertEqual(json.loads(response.data.decode('utf-8'))['data'], u'оживлённым')
def test_post_file_with_missing_content_type_header(self):
# I built up the form data manually here because I couldn't find a way
# to convince the werkzeug test client to send files without the