Skip to content

Commit

Permalink
JavaScript client sends query string attached to namespace
Browse files Browse the repository at this point in the history
Fixes #124
  • Loading branch information
miguelgrinberg committed Oct 1, 2017
1 parent 8bba811 commit 7f02f7a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions socketio/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def decode(self, encoded_packet):
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():
Expand Down
7 changes: 7 additions & 0 deletions tests/test_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def test_decode_namespace(self):
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')
Expand Down

0 comments on commit 7f02f7a

Please sign in to comment.