Skip to content

Commit

Permalink
parse integer packets as strings
Browse files Browse the repository at this point in the history
fixes #75
  • Loading branch information
miguelgrinberg committed Aug 25, 2018
1 parent a51feef commit 6735659
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions engineio/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,10 @@ def decode(self, encoded_packet):
try:
self.data = self.json.loads(
encoded_packet[1:].decode('utf-8'))
if isinstance(self.data, int):
# do not allow integer payloads, see
# github.com/miguelgrinberg/python-engineio/issues/75
# for background on this decision
raise ValueError
except ValueError:
self.data = encoded_packet[1:].decode('utf-8')
5 changes: 4 additions & 1 deletion tests/test_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ def test_encode_number_packet(self):
def test_decode_number_packet(self):
pkt = packet.Packet(encoded_packet=b'4123')
self.assertEqual(pkt.packet_type, packet.MESSAGE)
self.assertEqual(pkt.data, 123)
# integer payloads are parsed as strings, see
# https://github.com/miguelgrinberg/python-engineio/issues/75
# for background on this decision
self.assertEqual(pkt.data, '123')
self.assertFalse(pkt.binary)
self.assertEqual(pkt.encode(), b'4123')

0 comments on commit 6735659

Please sign in to comment.