Commits

Benjamin Peterson  committed 33e9a14

fix #4862 in _pyio: reset the decoder on seek(0)

  • Participants
  • Parent commits fbc7759

Comments (0)

Files changed (2)

File Lib/_pyio.py

         self._snapshot = None
 
         # Restore the decoder to its state from the safe start point.
-        if self._decoder or dec_flags or chars_to_skip:
+        if cookie == 0 and self._decoder:
+            self._decoder.reset()
+        elif self._decoder or dec_flags or chars_to_skip:
             self._decoder = self._decoder or self._get_decoder()
             self._decoder.setstate((b'', dec_flags))
             self._snapshot = (dec_flags, b'')

File Lib/test/test_io.py

             f.write(data)
             f.seek(0)
             self.assertEquals(f.read(), data * 2)
+            f.seek(0)
+            self.assertEquals(f.read(), data * 2)
             self.assertEquals(buf.getvalue(), (data * 2).encode(encoding))
 
     def test_read_one_by_one(self):