mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 22:14:55 -04:00
Do not use canonicaljson to magically handle decoding bytes from JSON. (#7802)
This commit is contained in:
parent
d9e47af617
commit
66a4af8d96
7 changed files with 17 additions and 28 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue