Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Fix issue with receiving 0-length strings & framed transport. #63

Merged
merged 1 commit into from
Nov 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/test_framed_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ def add(self, person):
self.registry[person.name] = person
return True

def get(self, name):
"""
Person get(1: string name)
"""
if name not in self.registry:
raise addressbook.PersonNotExistsError()
return self.registry[name]


class FramedTransportTestCase(TestCase):
def mk_server(self):
Expand Down Expand Up @@ -75,3 +83,10 @@ def test_able_to_communicate(self):
assert success
success = self.client.add(dennis)
assert not success

def test_zero_length_string(self):
dennis = addressbook.Person(name='')
success = self.client.add(dennis)
assert success
success = self.client.get(name='')
assert success
5 changes: 5 additions & 0 deletions thriftpy/transport/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ def close(self):
return self.__trans.close()

def read(self, sz):
# Important: don't attempt to read the next frame if the caller
# doesn't actually need any data.
if sz == 0:
return b''

ret = self.__rbuf.read(sz)
if len(ret) != 0:
return ret
Expand Down