diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py
index adc8804..98fbdfc 100644
a
|
b
|
class WSGIRequest(http.HttpRequest):
|
134 | 134 | # The WSGI spec says 'QUERY_STRING' may be absent. |
135 | 135 | raw_query_string = self.environ.get('QUERY_STRING', str('')) |
136 | 136 | if six.PY3: |
137 | | raw_query_string = raw_query_string.encode('iso-8859-1').decode('utf-8') |
| 137 | try: |
| 138 | # Assuming first that the query string has been utf-8 encoded |
| 139 | raw_query_string = raw_query_string.encode('iso-8859-1').decode('utf-8') |
| 140 | except UnicodeDecodeError: |
| 141 | pass |
138 | 142 | self._get = http.QueryDict(raw_query_string, encoding=self._encoding) |
139 | 143 | return self._get |
140 | 144 | |
diff --git a/tests/handlers/tests.py b/tests/handlers/tests.py
index f5dc7c8..99dc1ba 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).""" |