summary refs log tree commit diff
path: root/synapse/http/servlet.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-08-06 13:33:54 +0100
committerErik Johnston <erik@matrix.org>2018-08-06 13:33:54 +0100
commit49a316395831a0676160833c39daa0bb63ceea09 (patch)
treef1c4db4121d7890a7ba390c01b0e81e329f09b22 /synapse/http/servlet.py
parentMerge branch 'release-v0.33.1' of github.com:matrix-org/synapse into matrix-o... (diff)
parentReturn M_NOT_FOUND when a profile could not be found. (#3596) (diff)
downloadsynapse-49a316395831a0676160833c39daa0bb63ceea09.tar.xz
Merge branch 'develop' of github.com:matrix-org/synapse into matrix-org-hotfixes
Diffstat (limited to 'synapse/http/servlet.py')
-rw-r--r--synapse/http/servlet.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/synapse/http/servlet.py b/synapse/http/servlet.py

index 882816dc8f..69f7085291 100644 --- a/synapse/http/servlet.py +++ b/synapse/http/servlet.py
@@ -171,8 +171,16 @@ def parse_json_value_from_request(request, allow_empty_body=False): if not content_bytes and allow_empty_body: return None + # Decode to Unicode so that simplejson will return Unicode strings on + # Python 2 try: - content = json.loads(content_bytes) + content_unicode = content_bytes.decode('utf8') + except UnicodeDecodeError: + logger.warn("Unable to decode UTF-8") + raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON) + + try: + content = json.loads(content_unicode) except Exception as e: logger.warn("Unable to parse JSON: %s", e) raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON)