Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.0.X] Fixed #10687: fixed request parsing when upload_handlers is e…

…mpty. Thanks, Armin Ronacher. Backport of [10723] from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10765 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f4fce99bc1247f333c4093f3cfa077f7acd8d541 1 parent 11d08bc
Jacob Kaplan-Moss authored May 13, 2009
2  django/core/files/base.py
... ...
@@ -1,7 +1,5 @@
1 1
 import os
2  
-
3 2
 from django.utils.encoding import smart_str, smart_unicode
4  
-
5 3
 try:
6 4
     from cStringIO import StringIO
7 5
 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
@@ -294,3 +296,13 @@ def test_not_a_directory(self):
294 296
                               "%s exists and is not a directory." % UPLOAD_TO)
295 297
         except:
296 298
             self.fail("IOError not raised")
  299
+
  300
+class MultiParserTests(unittest.TestCase):
  301
+
  302
+    def test_empty_upload_handlers(self):
  303
+        # We're not actually parsing here; just checking if the parser properly
  304
+        # instantiates with empty upload handlers.
  305
+        parser = MultiPartParser({
  306
+            'CONTENT_TYPE':     'multipart/form-data; boundary=_foo',
  307
+            'CONTENT_LENGTH':   '1'
  308
+        }, StringIO('x'), [], 'utf-8')

0 notes on commit f4fce99

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