diff options
| author | Mehrdad <mhrddmoradii@gmail.com> | 2022-06-24 14:46:34 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-06-28 09:42:47 +0200 |
| commit | d4d5427571b4bf3a21c902276c2a00215c2a37cc (patch) | |
| tree | 59cc1bc214b414636b57b0e61fc6515a6e528f5f /tests/utils_tests/test_http.py | |
| parent | bff5c114be2b7a3fbc735c232abcc6ad4db89a9d (diff) | |
Refs #33697 -- Used django.utils.http.parse_header_parameters() for parsing boundary streams.
This also removes unused parse_header() and _parse_header_params()
helpers in django.http.multipartparser.
Diffstat (limited to 'tests/utils_tests/test_http.py')
| -rw-r--r-- | tests/utils_tests/test_http.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/utils_tests/test_http.py b/tests/utils_tests/test_http.py index 2ba617dfc9..b2754b4ddb 100644 --- a/tests/utils_tests/test_http.py +++ b/tests/utils_tests/test_http.py @@ -472,3 +472,41 @@ class ParseHeaderParameterTests(unittest.TestCase): for header, expected in tests: with self.subTest(header=header): self.assertEqual(parse_header_parameters(header), expected) + + def test_rfc2231_parsing(self): + test_data = ( + ( + "Content-Type: application/x-stuff; " + "title*=us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A", + "This is ***fun***", + ), + ( + "Content-Type: application/x-stuff; title*=UTF-8''foo-%c3%a4.html", + "foo-ä.html", + ), + ( + "Content-Type: application/x-stuff; title*=iso-8859-1''foo-%E4.html", + "foo-ä.html", + ), + ) + for raw_line, expected_title in test_data: + parsed = parse_header_parameters(raw_line) + self.assertEqual(parsed[1]["title"], expected_title) + + def test_rfc2231_wrong_title(self): + """ + Test wrongly formatted RFC 2231 headers (missing double single quotes). + Parsing should not crash (#24209). + """ + test_data = ( + ( + "Content-Type: application/x-stuff; " + "title*='This%20is%20%2A%2A%2Afun%2A%2A%2A", + "'This%20is%20%2A%2A%2Afun%2A%2A%2A", + ), + ("Content-Type: application/x-stuff; title*='foo.html", "'foo.html"), + ("Content-Type: application/x-stuff; title*=bar.html", "bar.html"), + ) + for raw_line, expected_title in test_data: + parsed = parse_header_parameters(raw_line) + self.assertEqual(parsed[1]["title"], expected_title) |
