Browse Source

JavaScript client sends query string attached to namespace

Fixes #124
pull/125/merge
Miguel Grinberg 8 years ago
parent
commit
7f02f7aaa9
No known key found for this signature in database GPG Key ID: 36848B262DF5F06C
  1. 3
      socketio/packet.py
  2. 7
      tests/test_packet.py

3
socketio/packet.py

@ -101,6 +101,9 @@ class Packet(object):
else: else:
self.namespace = ep[0:sep] self.namespace = ep[0:sep]
ep = ep[sep + 1:] ep = ep[sep + 1:]
q = self.namespace.find('?')
if q != -1:
self.namespace = self.namespace[0:q]
if ep and ep[0].isdigit(): if ep and ep[0].isdigit():
self.id = 0 self.id = 0
while ep[0].isdigit(): while ep[0].isdigit():

7
tests/test_packet.py

@ -97,6 +97,13 @@ class TestPacket(unittest.TestCase):
self.assertEqual(pkt.namespace, '/bar') self.assertEqual(pkt.namespace, '/bar')
self.assertEqual(pkt.encode(), '2/bar,["foo"]') 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): def test_encode_namespace_no_data(self):
pkt = packet.Packet(packet_type=packet.EVENT, namespace='/bar') pkt = packet.Packet(packet_type=packet.EVENT, namespace='/bar')
self.assertEqual(pkt.encode(), '2/bar') self.assertEqual(pkt.encode(), '2/bar')

Loading…
Cancel
Save