mirror of
https://github.com/python/cpython.git
synced 2025-08-24 10:45:53 +00:00
bpo-34523, bpo-35322: Fix unicode_encode_locale() (GH-10759)
Fix memory leak in PyUnicode_EncodeLocale() and PyUnicode_EncodeFSDefault() on error handling. Changes: * Fix unicode_encode_locale() error handling * Fix test_codecs.LocaleCodecTest
This commit is contained in:
parent
a22df4896f
commit
bde9d6bbb4
3 changed files with 19 additions and 9 deletions
|
@ -3290,9 +3290,9 @@ class LocaleCodecTest(unittest.TestCase):
|
|||
expected = text.encode(self.ENCODING, errors)
|
||||
except UnicodeEncodeError:
|
||||
with self.assertRaises(RuntimeError) as cm:
|
||||
self.encode(self.SURROGATES)
|
||||
self.encode(text, errors)
|
||||
errmsg = str(cm.exception)
|
||||
self.assertTrue(errmsg.startswith("encode error: pos=0, reason="), errmsg)
|
||||
self.assertRegex(errmsg, r"encode error: pos=[0-9]+, reason=")
|
||||
else:
|
||||
encoded = self.encode(text, errors)
|
||||
self.assertEqual(encoded, expected)
|
||||
|
@ -3315,6 +3315,11 @@ class LocaleCodecTest(unittest.TestCase):
|
|||
|
||||
self.check_encode_strings("surrogatepass")
|
||||
|
||||
def test_encode_unsupported_error_handler(self):
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
self.encode('', 'backslashreplace')
|
||||
self.assertEqual(str(cm.exception), 'unsupported error handler')
|
||||
|
||||
def decode(self, encoded, errors="strict"):
|
||||
return _testcapi.DecodeLocaleEx(encoded, 0, errors)
|
||||
|
||||
|
@ -3370,6 +3375,11 @@ class LocaleCodecTest(unittest.TestCase):
|
|||
|
||||
self.check_decode_strings("surrogatepass")
|
||||
|
||||
def test_decode_unsupported_error_handler(self):
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
self.decode(b'', 'backslashreplace')
|
||||
self.assertEqual(str(cm.exception), 'unsupported error handler')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue