Skip to content

Commit

Permalink
THRIFT-4206: Fix decoding of strings in containers with py:dynamic an…
Browse files Browse the repository at this point in the history
…d py:utf8strings

Client: py

_read_by_ttype and _write_by_ttype must be using the *element* spec
and not the container spec when determining the correct read/write
handler.

This closes apache#1273
  • Loading branch information
elprans authored and jeking3 committed Nov 30, 2017
1 parent 69a17f3 commit 82fa67f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/py/src/protocol/TProtocol.py
Expand Up @@ -268,7 +268,7 @@ def _ttype_handlers(self, ttype, spec):
return self._TTYPE_HANDLERS[ttype] if ttype < len(self._TTYPE_HANDLERS) else (None, None, False)

def _read_by_ttype(self, ttype, spec, espec):
reader_name, _, is_container = self._ttype_handlers(ttype, spec)
reader_name, _, is_container = self._ttype_handlers(ttype, espec)
if reader_name is None:
raise TProtocolException(type=TProtocolException.INVALID_DATA,
message='Invalid type %d' % (ttype))
Expand Down Expand Up @@ -389,7 +389,7 @@ def writeStruct(self, obj, thrift_spec):
self.writeStructEnd()

def _write_by_ttype(self, ttype, vals, spec, espec):
_, writer_name, is_container = self._ttype_handlers(ttype, spec)
_, writer_name, is_container = self._ttype_handlers(ttype, espec)
writer_func = getattr(self, writer_name)
write = (lambda v: writer_func(v, espec)) if is_container else writer_func
for v in vals:
Expand Down
4 changes: 4 additions & 0 deletions test/py/FastbinaryTest.py
Expand Up @@ -85,6 +85,10 @@ def isOpen(self):

hm.contain.add(("and a one", "and a two"))
hm.contain.add(("then a one, two", "three!", "FOUR!"))
if sys.version_info[0] == 2 and os.environ.get('THRIFT_TEST_PY_NO_UTF8STRINGS'):
hm.contain.add((u"\xd7\n\a\t".encode('utf8'),))
else:
hm.contain.add((u"\xd7\n\a\t",))
hm.contain.add(())

hm.bonks["nothing"] = []
Expand Down

0 comments on commit 82fa67f

Please sign in to comment.