Do not use canonicaljson to magically handle decoding bytes from JSON. (#7802)

This commit is contained in:
Patrick Cloke 2020-07-10 14:30:08 -04:00 committed by GitHub
parent d9e47af617
commit 66a4af8d96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 28 deletions

View file

@ -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)