diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2020-07-10 14:30:08 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-10 14:30:08 -0400 |
commit | 66a4af8d9627719a875c405c8c0f49b0056811b2 (patch) | |
tree | 8b489d82abe00793da78d40715dbb91731224044 /synapse/http/servlet.py | |
parent | Add types to the server code and remove unused parameter (#7813) (diff) | |
download | synapse-66a4af8d9627719a875c405c8c0f49b0056811b2.tar.xz |
Do not use canonicaljson to magically handle decoding bytes from JSON. (#7802)
Diffstat (limited to 'synapse/http/servlet.py')
-rw-r--r-- | synapse/http/servlet.py | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/synapse/http/servlet.py b/synapse/http/servlet.py index 13fcb408a6..3cabe9d02e 100644 --- a/synapse/http/servlet.py +++ b/synapse/http/servlet.py @@ -14,11 +14,9 @@ # limitations under the License. """ This module contains base REST classes for constructing REST servlets. """ - +import json import logging -from canonicaljson import json - from synapse.api.errors import Codes, SynapseError logger = logging.getLogger(__name__) @@ -214,16 +212,8 @@ 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_unicode = content_bytes.decode("utf8") - except UnicodeDecodeError: - logger.warning("Unable to decode UTF-8") - raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON) - try: - content = json.loads(content_unicode) + content = json.loads(content_bytes.decode("utf-8")) except Exception as e: logger.warning("Unable to parse JSON: %s", e) raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON) |