|
1 | 1 | import datetime |
| 2 | +import sys |
2 | 3 | import unittest |
3 | 4 | from unittest import mock |
4 | 5 | from urllib.parse import quote_plus |
5 | 6 |
|
6 | 7 | from django.test import SimpleTestCase |
7 | 8 | from django.utils.encoding import ( |
8 | 9 | DjangoUnicodeDecodeError, escape_uri_path, filepath_to_uri, force_bytes, |
9 | | - force_text, get_system_encoding, iri_to_uri, smart_bytes, smart_text, |
10 | | - uri_to_iri, |
| 10 | + force_text, get_system_encoding, iri_to_uri, repercent_broken_unicode, |
| 11 | + smart_bytes, smart_text, uri_to_iri, |
11 | 12 | ) |
12 | 13 | from django.utils.functional import SimpleLazyObject |
13 | 14 | from django.utils.translation import gettext_lazy |
@@ -86,6 +87,15 @@ def test_get_default_encoding(self): |
86 | 87 | with mock.patch('locale.getdefaultlocale', side_effect=Exception): |
87 | 88 | self.assertEqual(get_system_encoding(), 'ascii') |
88 | 89 |
|
| 90 | + def test_repercent_broken_unicode_recursion_error(self): |
| 91 | + # Prepare a string long enough to force a recursion error if the tested |
| 92 | + # function uses recursion. |
| 93 | + data = b'\xfc' * sys.getrecursionlimit() |
| 94 | + try: |
| 95 | + self.assertEqual(repercent_broken_unicode(data), b'%FC' * sys.getrecursionlimit()) |
| 96 | + except RecursionError: |
| 97 | + self.fail('Unexpected RecursionError raised.') |
| 98 | + |
89 | 99 |
|
90 | 100 | class TestRFC3987IEncodingUtils(unittest.TestCase): |
91 | 101 |
|
|
0 commit comments