diff --git a/django/http/request.py b/django/http/request.py
index c87a4c5..94f08ff 100644
a
|
b
|
class QueryDict(MultiValueDict):
|
329 | 329 | self.encoding = encoding |
330 | 330 | if six.PY3: |
331 | 331 | 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') |
334 | 338 | for key, value in parse_qsl(query_string or '', |
335 | 339 | keep_blank_values=True, |
336 | 340 | encoding=encoding): |
diff --git a/tests/handlers/tests.py b/tests/handlers/tests.py
index 178f42d..b8bc696 100644
a
|
b
|
class HandlerTests(TestCase):
|
44 | 44 | def test_non_ascii_query_string(self): |
45 | 45 | """Test that non-ASCII query strings are properly decoded (#20530).""" |
46 | 46 | 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é']) |
53 | 57 | |
54 | 58 | def test_non_ascii_cookie(self): |
55 | 59 | """Test that non-ASCII cookies set in JavaScript are properly decoded (#20557).""" |