Skip to content

Commit

Permalink
support packets with empty payload given as an integer
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Oct 30, 2015
1 parent ee63afe commit d31d167
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion socketio/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ def decode(self, encoded_packet):
necessary to fully decode the packet.
"""
ep = encoded_packet
self.packet_type = int(ep[0:1])
try:
self.packet_type = int(ep[0:1])
except TypeError:
self.packet_type = ep
ep = ''
self.namespace = None
self.data = None
ep = ep[1:]
Expand Down
7 changes: 7 additions & 0 deletions tests/test_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def test_decode_text_event_packet(self):
self.assertEqual(pkt.data, ['foo'])
self.assertEqual(pkt.encode(), '2["foo"]')

def test_decode_empty_event_packet(self):
pkt = packet.Packet(encoded_packet='1')
self.assertEqual(pkt.packet_type, packet.DISCONNECT)
# same thing, but with a numeric payload
pkt = packet.Packet(encoded_packet=1)
self.assertEqual(pkt.packet_type, packet.DISCONNECT)

def test_encode_binary_event_packet(self):
pkt = packet.Packet(packet_type=packet.EVENT, data=b'1234')
self.assertEqual(pkt.packet_type, packet.BINARY_EVENT)
Expand Down

0 comments on commit d31d167

Please sign in to comment.