From 3d10d82d0e8f1b0fbd50aeba0c8f8bae15010217 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Thu, 31 Oct 2019 12:26:53 +0100 Subject: [PATCH] parsers: Inline fp.read() of json.load in JSONParser This enables upcoming inspection of the decoded data on string level, prior to parsing JSON. --- rest_framework/parsers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rest_framework/parsers.py b/rest_framework/parsers.py index 79ea5133f..9bfe2e69c 100644 --- a/rest_framework/parsers.py +++ b/rest_framework/parsers.py @@ -61,8 +61,8 @@ class JSONParser(BaseParser): encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET) try: - decoded_stream = codecs.getreader(encoding)(stream) - return json.load(decoded_stream, parse_constant=parse_constant) + decoded_string = codecs.getreader(encoding)(stream).read() + return json.loads(decoded_string, parse_constant=parse_constant) except ValueError as exc: raise ParseError('JSON parse error - %s' % str(exc))