]> granicus.if.org Git - python/commitdiff
Merged revisions 88546 via svnmerge from
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>
Thu, 24 Feb 2011 20:34:38 +0000 (20:34 +0000)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>
Thu, 24 Feb 2011 20:34:38 +0000 (20:34 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r88546 | alexander.belopolsky | 2011-02-24 14:40:09 -0500 (Thu, 24 Feb 2011) | 3 lines

  Issue #11286: Fixed unpickling of empty 2.x strings.
........

Lib/test/pickletester.py
Lib/test/test_pickle.py
Lib/test/test_pickletools.py
Modules/_pickle.c

index 3ae7defa648533a9e1cddbfc59462feb17fb223a..a843486a42aba6b6052917b1e3e54ff3420c8c20 100644 (file)
@@ -1093,6 +1093,10 @@ class AbstractPickleTests(unittest.TestCase):
             self.assertEqual(len(loaded), len(data))
             self.assertEqual(loaded, data)
 
+    def test_empty_bytestring(self):
+        # issue 11286
+        empty = self.loads(b'\x80\x03U\x00q\x00.', encoding='koi8-r')
+        self.assertEqual(empty, '')
 
 # Test classes for reduce_ex
 
index 7f642c8b80f1e0d8d1df75c107f5e8fe4f7ace72..a3878fd62a62d2f771170555e7bd0463db96946b 100644 (file)
@@ -31,9 +31,9 @@ class PyPicklerTests(AbstractPickleTests):
         f.seek(0)
         return bytes(f.read())
 
-    def loads(self, buf):
+    def loads(self, buf, **kwds):
         f = io.BytesIO(buf)
-        u = self.unpickler(f)
+        u = self.unpickler(f, **kwds)
         return u.load()
 
 
@@ -45,8 +45,8 @@ class InMemoryPickleTests(AbstractPickleTests):
     def dumps(self, arg, proto=None):
         return pickle.dumps(arg, proto)
 
-    def loads(self, buf):
-        return pickle.loads(buf)
+    def loads(self, buf, **kwds):
+        return pickle.loads(buf, **kwds)
 
 
 class PyPersPicklerTests(AbstractPersistentPicklerTests):
@@ -64,12 +64,12 @@ class PyPersPicklerTests(AbstractPersistentPicklerTests):
         f.seek(0)
         return f.read()
 
-    def loads(self, buf):
+    def loads(self, buf, **kwds):
         class PersUnpickler(self.unpickler):
             def persistent_load(subself, obj):
                 return self.persistent_load(obj)
         f = io.BytesIO(buf)
-        u = PersUnpickler(f)
+        u = PersUnpickler(f, **kwds)
         return u.load()
 
 
index 823b0c2621f80609fb7c54168bbc684a6aba03ad..d37ac263c4c14f3f3bc645ab78446d93a75a3001 100644 (file)
@@ -9,8 +9,8 @@ class OptimizedPickleTests(AbstractPickleTests, AbstractPickleModuleTests):
     def dumps(self, arg, proto=None):
         return pickletools.optimize(pickle.dumps(arg, proto))
 
-    def loads(self, buf):
-        return pickle.loads(buf)
+    def loads(self, buf, **kwds):
+        return pickle.loads(buf, **kwds)
 
     # Test relies on precise output of dumps()
     test_pickle_to_2x = None
index b01a8b275c70af960004ef3c840ad38beaaaf5f5..fb6281ee3a72d1e4e99a3b1d7a8d0d5f8daf4620 100644 (file)
@@ -977,11 +977,6 @@ _Unpickler_Read(UnpicklerObject *self, char **s, Py_ssize_t n)
 {
     Py_ssize_t num_read;
 
-    if (n == 0) {
-        *s = NULL;
-        return 0;
-    }
-
     if (self->next_read_idx + n <= self->input_len) {
         *s = self->input_buffer + self->next_read_idx;
         self->next_read_idx += n;