summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-09-16 14:31:06 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2016-09-16 14:31:06 (GMT)
commit4a72a7b6c4c95f7613486f0e4e20a3d4815a16c5 (patch)
treeb324021153abfe7835d6793a5ff6bacdae805131 /Lib/test/test_codecs.py
parenta4961e555b9b6b684f123cdbe426b4da22a1b460 (diff)
downloadcpython-4a72a7b6c4c95f7613486f0e4e20a3d4815a16c5.zip
cpython-4a72a7b6c4c95f7613486f0e4e20a3d4815a16c5.tar.gz
cpython-4a72a7b6c4c95f7613486f0e4e20a3d4815a16c5.tar.bz2
Issue #25270: Prevent codecs.escape_encode() from raising SystemError when an empty bytestring is passed
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r--Lib/test/test_codecs.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 0479542..013ec64 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -2501,6 +2501,26 @@ class RawUnicodeEscapeTest(unittest.TestCase):
self.assertEqual(decode(br"\U00110000", "replace"), ("\ufffd", 10))
+class EscapeEncodeTest(unittest.TestCase):
+
+ def test_escape_encode(self):
+ tests = [
+ (b'', (b'', 0)),
+ (b'foobar', (b'foobar', 6)),
+ (b'spam\0eggs', (b'spam\\x00eggs', 9)),
+ (b'a\'b', (b"a\\'b", 3)),
+ (b'b\\c', (b'b\\\\c', 3)),
+ (b'c\nd', (b'c\\nd', 3)),
+ (b'd\re', (b'd\\re', 3)),
+ (b'f\x7fg', (b'f\\x7fg', 3)),
+ ]
+ for data, output in tests:
+ with self.subTest(data=data):
+ self.assertEqual(codecs.escape_encode(data), output)
+ self.assertRaises(TypeError, codecs.escape_encode, 'spam')
+ self.assertRaises(TypeError, codecs.escape_encode, bytearray(b'spam'))
+
+
class SurrogateEscapeTest(unittest.TestCase):
def test_utf8(self):