diff --git a/socketio/packet.py b/socketio/packet.py index dd9f859..570708b 100644 --- a/socketio/packet.py +++ b/socketio/packet.py @@ -101,6 +101,9 @@ class Packet(object): else: self.namespace = ep[0:sep] ep = ep[sep + 1:] + q = self.namespace.find('?') + if q != -1: + self.namespace = self.namespace[0:q] if ep and ep[0].isdigit(): self.id = 0 while ep[0].isdigit(): diff --git a/tests/test_packet.py b/tests/test_packet.py index f4d2207..9602789 100644 --- a/tests/test_packet.py +++ b/tests/test_packet.py @@ -97,6 +97,13 @@ class TestPacket(unittest.TestCase): self.assertEqual(pkt.namespace, '/bar') self.assertEqual(pkt.encode(), '2/bar,["foo"]') + def test_decode_namespace_with_query_string(self): + # some Socket.IO clients mistakenly attach the query string to the + # namespace + pkt = packet.Packet(encoded_packet='2/bar?a=b,["foo"]') + self.assertEqual(pkt.namespace, '/bar') + self.assertEqual(pkt.encode(), '2/bar,["foo"]') + def test_encode_namespace_no_data(self): pkt = packet.Packet(packet_type=packet.EVENT, namespace='/bar') self.assertEqual(pkt.encode(), '2/bar')