Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.3.x] Fixed #15496 -- Corrected handling of base64 file upload enco…

…ding. Backport of r16176 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.3.X@17546 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 813dc01cd88e13b4d125cb24061ebb86c7ce3b09 1 parent c63a454
@aaugustin aaugustin authored
View
2  django/http/multipartparser.py
@@ -150,6 +150,8 @@ def parse(self):
continue
transfer_encoding = meta_data.get('content-transfer-encoding')
+ if transfer_encoding is not None:
+ transfer_encoding = transfer_encoding[0].strip()
field_name = force_unicode(field_name, encoding, errors='replace')
if item_type == FIELD:
View
25 tests/regressiontests/file_uploads/tests.py
@@ -1,5 +1,6 @@
#! -*- coding: utf-8 -*-
import errno
+import base64
import os
import shutil
from StringIO import StringIO
@@ -55,6 +56,30 @@ def test_large_upload(self):
self.assertEqual(response.status_code, 200)
+ def test_base64_upload(self):
+ test_string = "This data will be transmitted base64-encoded."
+ payload = "\r\n".join([
+ '--' + client.BOUNDARY,
+ 'Content-Disposition: form-data; name="file"; filename="test.txt"',
+ 'Content-Type: application/octet-stream',
+ 'Content-Transfer-Encoding: base64',
+ '',
+ base64.b64encode(test_string),
+ '--' + client.BOUNDARY + '--',
+ '',
+ ])
+ r = {
+ 'CONTENT_LENGTH': len(payload),
+ 'CONTENT_TYPE': client.MULTIPART_CONTENT,
+ 'PATH_INFO': "/file_uploads/echo_content/",
+ 'REQUEST_METHOD': 'POST',
+ 'wsgi.input': client.FakePayload(payload),
+ }
+ response = self.client.request(**r)
+ received = simplejson.loads(response.content)
+
+ self.assertEqual(received['file'], test_string)
+
def test_unicode_file_name(self):
tdir = tempfile.gettempdir()
View
1  tests/regressiontests/file_uploads/urls.py
@@ -6,6 +6,7 @@
(r'^verify/$', views.file_upload_view_verify),
(r'^unicode_name/$', views.file_upload_unicode_name),
(r'^echo/$', views.file_upload_echo),
+ (r'^echo_content/$', views.file_upload_echo_content),
(r'^quota/$', views.file_upload_quota),
(r'^quota/broken/$', views.file_upload_quota_broken),
(r'^getlist_count/$', views.file_upload_getlist_count),
View
7 tests/regressiontests/file_uploads/views.py
@@ -85,6 +85,13 @@ def file_upload_echo(request):
r = dict([(k, f.name) for k, f in request.FILES.items()])
return HttpResponse(simplejson.dumps(r))
+def file_upload_echo_content(request):
+ """
+ Simple view to echo back the content of uploaded files for tests.
+ """
+ r = dict([(k, f.read()) for k, f in request.FILES.items()])
+ return HttpResponse(simplejson.dumps(r))
+
def file_upload_quota(request):
"""
Dynamically add in an upload handler.
Please sign in to comment.
Something went wrong with that request. Please try again.