From 7f02f7aaa92c18c043466cb4721356221361f481 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Sun, 1 Oct 2017 16:47:46 -0700 Subject: [PATCH] JavaScript client sends query string attached to namespace Fixes #124 --- socketio/packet.py | 3 +++ tests/test_packet.py | 7 +++++++ 2 files changed, 10 insertions(+) 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')