Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10687: fixed request parsing when upload_handlers is empty. Th…

…anks, Armin Ronacher.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10723 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c40f715257b6268cfd96dbafa18e58cbc6602afa 1 parent 88f5167
Jacob Kaplan-Moss authored
1  django/core/files/base.py
... ...
@@ -1,5 +1,4 @@
1 1
 import os
2  
-
3 2
 try:
4 3
     from cStringIO import StringIO
5 4
 except ImportError:
3  django/http/multipartparser.py
@@ -84,7 +84,8 @@ def __init__(self, META, input_data, upload_handlers, encoding=None):
84 84
 
85 85
         # For compatibility with low-level network APIs (with 32-bit integers),
86 86
         # the chunk size should be < 2^31, but still divisible by 4.
87  
-        self._chunk_size = min(2**31-4, *[x.chunk_size for x in upload_handlers if x.chunk_size])
  87
+        possible_sizes = [x.chunk_size for x in upload_handlers if x.chunk_size]
  88
+        self._chunk_size = min([2**31-4] + possible_sizes)
88 89
 
89 90
         self._meta = META
90 91
         self._encoding = encoding or settings.DEFAULT_CHARSET
12  tests/regressiontests/file_uploads/tests.py
@@ -3,12 +3,14 @@
3 3
 import errno
4 4
 import shutil
5 5
 import unittest
  6
+from StringIO import StringIO
6 7
 
7 8
 from django.core.files import temp as tempfile
8 9
 from django.core.files.uploadedfile import SimpleUploadedFile
9 10
 from django.test import TestCase, client
10 11
 from django.utils import simplejson
11 12
 from django.utils.hashcompat import sha_constructor
  13
+from django.http.multipartparser import MultiPartParser
12 14
 
13 15
 from models import FileModel, temp_storage, UPLOAD_TO
14 16
 import uploadhandler
@@ -290,3 +292,13 @@ def test_not_a_directory(self):
290 292
                               "%s exists and is not a directory." % UPLOAD_TO)
291 293
         except:
292 294
             self.fail("IOError not raised")
  295
+
  296
+class MultiParserTests(unittest.TestCase):
  297
+
  298
+    def test_empty_upload_handlers(self):
  299
+        # We're not actually parsing here; just checking if the parser properly
  300
+        # instantiates with empty upload handlers.
  301
+        parser = MultiPartParser({
  302
+            'CONTENT_TYPE':     'multipart/form-data; boundary=_foo',
  303
+            'CONTENT_LENGTH':   '1'
  304
+        }, StringIO('x'), [], 'utf-8')

0 notes on commit c40f715

Please sign in to comment.
Something went wrong with that request. Please try again.