[Python-checkins] cpython (2.7): Backported tests for issue #22406.

serhiy.storchaka python-checkins at python.org
Fri Nov 7 13:12:47 CET 2014


https://hg.python.org/cpython/rev/7b82b58b8329
changeset:   93429:7b82b58b8329
branch:      2.7
parent:      93424:e80cb046e764
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Fri Nov 07 14:07:43 2014 +0200
summary:
  Backported tests for issue #22406.

files:
  Lib/test/test_codecs.py |   4 ++++
  Lib/test/test_uu.py     |  20 ++++++++++++++++++++
  2 files changed, 24 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -2109,6 +2109,10 @@
         BomTest,
     )
 
+    def test_uu_invalid(self):
+        # Missing "begin" line
+        self.assertRaises(ValueError, codecs.decode, "", "uu-codec")
+
 
 if __name__ == "__main__":
     test_main()
diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py
--- a/Lib/test/test_uu.py
+++ b/Lib/test/test_uu.py
@@ -61,6 +61,26 @@
         except uu.Error, e:
             self.assertEqual(str(e), "No valid begin line found in input file")
 
+    def test_garbage_padding(self):
+        # Issue #22406
+        encodedtext = (
+            "begin 644 file\n"
+            # length 1; bits 001100 111111 111111 111111
+            "\x21\x2C\x5F\x5F\x5F\n"
+            "\x20\n"
+            "end\n"
+        )
+        plaintext = "\x33"  # 00110011
+
+        inp = cStringIO.StringIO(encodedtext)
+        out = cStringIO.StringIO()
+        uu.decode(inp, out, quiet=True)
+        self.assertEqual(out.getvalue(), plaintext)
+
+        import codecs
+        decoded = codecs.decode(encodedtext, "uu_codec")
+        self.assertEqual(decoded, plaintext)
+
 class UUStdIOTest(unittest.TestCase):
 
     def setUp(self):

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list