Ticket #28678: multiparser_json.diff
File multiparser_json.diff, 2.2 KB (added by , 7 years ago) |
---|
-
multipartparser.py
old new 9 9 import base64 10 10 import binascii 11 11 import cgi 12 import json 12 13 import sys 13 14 14 15 from django.conf import settings … … 175 176 if item_type == FIELD: 176 177 # Avoid storing more than DATA_UPLOAD_MAX_NUMBER_FIELDS. 177 178 num_post_keys += 1 179 text_info = True 178 180 if (settings.DATA_UPLOAD_MAX_NUMBER_FIELDS is not None and 179 181 settings.DATA_UPLOAD_MAX_NUMBER_FIELDS < num_post_keys): 180 182 raise TooManyFieldsSent( … … 194 196 data = base64.b64decode(raw_data) 195 197 except _BASE64_DECODE_ERROR: 196 198 data = raw_data 199 elif 'content-type' in meta_data and meta_data['content-type'][0].strip() == 'application/json': 200 raw_data = field_stream.read(size=read_size) 201 num_bytes_read += len(raw_data) 202 try: 203 data = json.loads(raw_data) 204 text_info = False 205 except ValueError: 206 data = raw_data 197 207 else: 198 208 data = field_stream.read(size=read_size) 199 209 num_bytes_read += len(data) … … 205 215 num_bytes_read > settings.DATA_UPLOAD_MAX_MEMORY_SIZE): 206 216 raise RequestDataTooBig('Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.') 207 217 208 self._post.appendlist(field_name, force_text(data, encoding, errors='replace')) 218 if text_info: 219 self._post.appendlist(field_name, force_text(data, encoding, errors='replace')) 220 else: 221 self._post.appendlist(field_name, data) 209 222 elif item_type == FILE: 210 223 # This is a file, use the handler... 211 224 file_name = disposition.get('filename')