Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[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
@jacobian jacobian authored
View
2  django/core/files/base.py
@@ -1,7 +1,5 @@
import os
-
from django.utils.encoding import smart_str, smart_unicode
-
try:
from cStringIO import StringIO
except ImportError:
View
3  django/http/multipartparser.py
@@ -84,7 +84,8 @@ def __init__(self, META, input_data, upload_handlers, encoding=None):
# For compatibility with low-level network APIs (with 32-bit integers),
# the chunk size should be < 2^31, but still divisible by 4.
- self._chunk_size = min(2**31-4, *[x.chunk_size for x in upload_handlers if x.chunk_size])
+ possible_sizes = [x.chunk_size for x in upload_handlers if x.chunk_size]
+ self._chunk_size = min([2**31-4] + possible_sizes)
self._meta = META
self._encoding = encoding or settings.DEFAULT_CHARSET
View
12 tests/regressiontests/file_uploads/tests.py
@@ -3,12 +3,14 @@
import errno
import shutil
import unittest
+from StringIO import StringIO
from django.core.files import temp as tempfile
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase, client
from django.utils import simplejson
from django.utils.hashcompat import sha_constructor
+from django.http.multipartparser import MultiPartParser
from models import FileModel, temp_storage, UPLOAD_TO
import uploadhandler
@@ -294,3 +296,13 @@ def test_not_a_directory(self):
"%s exists and is not a directory." % UPLOAD_TO)
except:
self.fail("IOError not raised")
+
+class MultiParserTests(unittest.TestCase):
+
+ def test_empty_upload_handlers(self):
+ # We're not actually parsing here; just checking if the parser properly
+ # instantiates with empty upload handlers.
+ parser = MultiPartParser({
+ 'CONTENT_TYPE': 'multipart/form-data; boundary=_foo',
+ 'CONTENT_LENGTH': '1'
+ }, StringIO('x'), [], 'utf-8')

0 comments on commit f4fce99

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