Ticket #19036: 19036-2.diff

File 19036-2.diff, 2.5 KB (added by johannesl, 12 years ago)

Corrections for stable/1.5.x branch

  • django/http/multipartparser.py

    diff --git a/django/http/multipartparser.py b/django/http/multipartparser.py
    index 9413a1e..edf98f6 100644
    a b class MultiPartParser(object):  
    199199                        for chunk in field_stream:
    200200                            if transfer_encoding == 'base64':
    201201                                # We only special-case base64 transfer encoding
     202                                # We should always read base64 streams by multiple of 4
     203                                over_bytes = len(chunk) % 4
     204                                if over_bytes:
     205                                    over_chunk = field_stream.read(4 - over_bytes)
     206                                    chunk += over_chunk
     207
    202208                                try:
    203209                                    chunk = base64.b64decode(chunk)
    204210                                except Exception as e:
  • tests/regressiontests/file_uploads/tests.py

    diff --git a/tests/regressiontests/file_uploads/tests.py b/tests/regressiontests/file_uploads/tests.py
    index 8fa140b..124ba5d 100644
    a b class FileUploadTests(TestCase):  
    7474
    7575        self.assertEqual(response.status_code, 200)
    7676
    77     def test_base64_upload(self):
    78         test_string = "This data will be transmitted base64-encoded."
     77    def _test_base64_upload(self,content):
    7978        payload = client.FakePayload("\r\n".join([
    8079            '--' + client.BOUNDARY,
    8180            'Content-Disposition: form-data; name="file"; filename="test.txt"',
    8281            'Content-Type: application/octet-stream',
    8382            'Content-Transfer-Encoding: base64',
    8483            '',]))
    85         payload.write(b"\r\n" + base64.b64encode(force_bytes(test_string)) + b"\r\n")
     84        payload.write(b"\r\n" + base64.b64encode(force_bytes(content)) + b"\r\n")
    8685        payload.write('--' + client.BOUNDARY + '--\r\n')
    8786        r = {
    8887            'CONTENT_LENGTH': len(payload),
    class FileUploadTests(TestCase):  
    9493        response = self.client.request(**r)
    9594        received = json.loads(response.content.decode('utf-8'))
    9695
    97         self.assertEqual(received['file'], test_string)
     96        self.assertEqual(received['file'], content)
     97
     98    def test_base64_upload(self):
     99        self._test_base64_upload("This data will be transmitted base64-encoded.")
     100
     101    def test_big_base64_upload(self):
     102        self._test_base64_upload("Big data" * 68000)  # > 512Kb
    98103
    99104    def test_unicode_file_name(self):
    100105        tdir = sys_tempfile.mkdtemp()
Back to Top