Ticket #22996: 22996-master.diff

File 22996-master.diff, 2.2 KB (added by Claude Paroz, 10 years ago)
  • django/http/request.py

    diff --git a/django/http/request.py b/django/http/request.py
    index c87a4c5..94f08ff 100644
    a b class QueryDict(MultiValueDict):  
    329329        self.encoding = encoding
    330330        if six.PY3:
    331331            if isinstance(query_string, bytes):
    332                 # query_string contains URL-encoded data, a subset of ASCII.
    333                 query_string = query_string.decode()
     332                # query_string normally contains URL-encoded data, a subset of ASCII.
     333                try:
     334                    query_string = query_string.decode()
     335                except UnicodeDecodeError:
     336                    # ... but some user agents are misbehaving :-(
     337                    query_string = query_string.decode('latin1')
    334338            for key, value in parse_qsl(query_string or '',
    335339                                        keep_blank_values=True,
    336340                                        encoding=encoding):
  • tests/handlers/tests.py

    diff --git a/tests/handlers/tests.py b/tests/handlers/tests.py
    index 178f42d..b8bc696 100644
    a b class HandlerTests(TestCase):  
    4444    def test_non_ascii_query_string(self):
    4545        """Test that non-ASCII query strings are properly decoded (#20530)."""
    4646        environ = RequestFactory().get('/').environ
    47         raw_query_string = 'want=café'
    48         if six.PY3:
    49             raw_query_string = raw_query_string.encode('utf-8').decode('iso-8859-1')
    50         environ['QUERY_STRING'] = raw_query_string
    51         request = WSGIRequest(environ)
    52         self.assertEqual(request.GET['want'], "café")
     47        raw_query_strings = ['want=café', 'want=cafÃ', 'want=café']
     48        got = []
     49        for raw_query_string in raw_query_strings:
     50            environ['QUERY_STRING'] = raw_query_string
     51            request = WSGIRequest(environ)
     52            got.append(request.GET['want'])
     53        if six.PY2:
     54            self.assertListEqual(got, ['café', 'cafÃ', 'café'])
     55        else:
     56            self.assertListEqual(got, ['café', 'cafÃ', 'café'])
    5357
    5458    def test_non_ascii_cookie(self):
    5559        """Test that non-ASCII cookies set in JavaScript are properly decoded (#20557)."""
Back to Top