Non-ASCII query strings are properly decoded (#20530, #22996).
(self)
| 35 | self.assertEqual(response.status_code, 404) |
| 36 | |
| 37 | def test_non_ascii_query_string(self): |
| 38 | """ |
| 39 | Non-ASCII query strings are properly decoded (#20530, #22996). |
| 40 | """ |
| 41 | environ = self.request_factory.get("/").environ |
| 42 | raw_query_strings = [ |
| 43 | b"want=caf%C3%A9", # This is the proper way to encode 'café' |
| 44 | b"want=caf\xc3\xa9", # UA forgot to quote bytes |
| 45 | b"want=caf%E9", # UA quoted, but not in UTF-8 |
| 46 | # UA forgot to convert Latin-1 to UTF-8 and to quote (typical of |
| 47 | # MSIE). |
| 48 | b"want=caf\xe9", |
| 49 | ] |
| 50 | got = [] |
| 51 | for raw_query_string in raw_query_strings: |
| 52 | # Simulate http.server.BaseHTTPRequestHandler.parse_request |
| 53 | # handling of raw request. |
| 54 | environ["QUERY_STRING"] = str(raw_query_string, "iso-8859-1") |
| 55 | request = WSGIRequest(environ) |
| 56 | got.append(request.GET["want"]) |
| 57 | # %E9 is converted to the Unicode replacement character by parse_qsl |
| 58 | self.assertEqual(got, ["café", "café", "caf\ufffd", "café"]) |
| 59 | |
| 60 | def test_non_ascii_cookie(self): |
| 61 | """ |
nothing calls this directly
no test coverage detected