diff options
author | Inada Naoki <songofacandy@gmail.com> | 2019-12-06 21:16:27 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-06 21:16:27 +0900 |
commit | f6f6f328eb2d7b7f1272fa7addb31d2ac5bef207 (patch) | |
tree | 2d5d5507d4c1bef2cb88687c9fd24f72503566e6 | |
parent | 7a8ce0f9ca910a851b6835d26b1d6970a188fa4e (diff) | |
download | msgpack-python-f6f6f328eb2d7b7f1272fa7addb31d2ac5bef207.tar.gz |
Fix fallback Unpacker.read() (#388)
Fixes #352.
-rw-r--r-- | msgpack/fallback.py | 4 | ||||
-rw-r--r-- | test/test_sequnpack.py | 9 |
2 files changed, 12 insertions, 1 deletions
diff --git a/msgpack/fallback.py b/msgpack/fallback.py index 388a5ab..85a711b 100644 --- a/msgpack/fallback.py +++ b/msgpack/fallback.py @@ -357,7 +357,9 @@ class Unpacker(object): return self._buffer[self._buff_i :] def read_bytes(self, n): - return self._read(n) + ret = self._read(n) + self._consume() + return ret def _read(self, n): # (int) -> bytearray diff --git a/test/test_sequnpack.py b/test/test_sequnpack.py index 9b69479..ad29de8 100644 --- a/test/test_sequnpack.py +++ b/test/test_sequnpack.py @@ -93,6 +93,15 @@ def test_readbytes(): assert unpacker.unpack() == ord(b"a") assert unpacker.unpack() == ord(b"r") + # Issue 352 + u = Unpacker() + u.feed(b"x") + assert bytes(u.read_bytes(1)) == b"x" + with raises(StopIteration): + next(u) + u.feed(b"\1") + assert next(u) == 1 + def test_issue124(): unpacker = Unpacker() |