diff --git a/socketio/packet.py b/socketio/packet.py index 642e179..9877a22 100644 --- a/socketio/packet.py +++ b/socketio/packet.py @@ -69,7 +69,11 @@ class Packet(object): 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:] diff --git a/tests/test_packet.py b/tests/test_packet.py index 511cee1..af77e8d 100644 --- a/tests/test_packet.py +++ b/tests/test_packet.py @@ -32,6 +32,13 @@ class TestPacket(unittest.TestCase): 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)