Ticket #19101: 19101-3.diff

File 19101-3.diff, 2.5 KB (added by Aymeric Augustin, 12 years ago)
  • django/http/multipartparser.py

    diff --git a/django/http/multipartparser.py b/django/http/multipartparser.py
    index 40aefd6..5bcc874 100644
    a b class MultiPartParser(object):  
    110110        # HTTP spec says that Content-Length >= 0 is valid
    111111        # handling content-length == 0 before continuing
    112112        if self._content_length == 0:
    113             return QueryDict(MultiValueDict(), encoding=self._encoding), MultiValueDict()
     113            return QueryDict('', encoding=self._encoding), MultiValueDict()
    114114
    115115        # See if the handler will want to take care of the parsing.
    116116        # This allows overriding everything if somebody wants it.
  • django/http/request.py

    diff --git a/django/http/request.py b/django/http/request.py
    index 96c7606..75fe4d3 100644
    a b class QueryDict(MultiValueDict):  
    276276            encoding = settings.DEFAULT_CHARSET
    277277        self.encoding = encoding
    278278        if six.PY3:
     279            query_string = force_text(query_string, encoding, errors='replace')
    279280            for key, value in parse_qsl(query_string or '',
    280281                                        keep_blank_values=True,
    281282                                        encoding=encoding):
  • tests/regressiontests/requests/tests.py

    diff --git a/tests/regressiontests/requests/tests.py b/tests/regressiontests/requests/tests.py
    index eaf25ea..164c108 100644
    a b from django.http import HttpRequest, HttpResponse, parse_cookie, build_request_r  
    1212from django.test.client import FakePayload
    1313from django.test.utils import override_settings, str_prefix
    1414from django.utils import unittest
    15 from django.utils.http import cookie_date
     15from django.utils.http import cookie_date, urlencode
    1616from django.utils.timezone import utc
    1717
    1818
    class RequestsTests(unittest.TestCase):  
    353353        self.assertRaises(Exception, lambda: request.body)
    354354        self.assertEqual(request.POST, {})
    355355
     356    def test_non_ascii_POST(self):
     357        payload = FakePayload(urlencode({'key': 'España'}))
     358        request = WSGIRequest({
     359            'REQUEST_METHOD': 'POST',
     360            'CONTENT_LENGTH': len(payload),
     361            'CONTENT_TYPE': 'application/x-www-form-urlencoded',
     362            'wsgi.input': payload,
     363        })
     364        self.assertEqual(request.POST, {'key': ['España']})
     365
    356366    def test_alternate_charset_POST(self):
    357367        """
    358368        Test a POST with non-utf-8 payload encoding.
Back to Top