diff options
author | Victor Stinner <vstinner@redhat.com> | 2018-11-28 09:26:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-28 09:26:20 (GMT) |
commit | bde9d6bbb46ca59bcee5d5060adaa33c3ffee3a6 (patch) | |
tree | ef525570f785225ab3da54b867b2ea4cb137fb40 /Lib/test/test_codecs.py | |
parent | a22df4896f6b83c8741203118790ae281716bca5 (diff) | |
download | cpython-bde9d6bbb46ca59bcee5d5060adaa33c3ffee3a6.zip cpython-bde9d6bbb46ca59bcee5d5060adaa33c3ffee3a6.tar.gz cpython-bde9d6bbb46ca59bcee5d5060adaa33c3ffee3a6.tar.bz2 |
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
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r-- | Lib/test/test_codecs.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 00b5d31..8c92556 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -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() |