Skip to content

Commit

Permalink
Fixed incorrect handling of dashes inside the JSON payload of a packet (
Browse files Browse the repository at this point in the history
Fixes #675)
  • Loading branch information
miguelgrinberg committed Apr 18, 2021
1 parent 1f0c8c6 commit f4e1010
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions socketio/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ def decode(self, encoded_packet):
self.data = None
ep = ep[1:]
dash = ep.find('-')
if dash > 10:
raise ValueError('too many attachments')
attachment_count = 0
if dash > 0 and ep[0:dash].isdigit():
if dash > 10:
raise ValueError('too many attachments')
attachment_count = int(ep[0:dash])
ep = ep[dash + 1:]
if ep and ep[0:1] == '/':
Expand Down
7 changes: 6 additions & 1 deletion tests/common/test_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,12 @@ def test_decode_too_many_binary_packets(self):

def test_decode_attachment_count_too_long(self):
with pytest.raises(ValueError):
packet.Packet(encoded_packet='6' + ('1' * 11) + '-{"a":"123}')
packet.Packet(encoded_packet='6' + ('1' * 11) + '-{"a":"123"}')

def test_decode_dash_in_payload(self):
pkt = packet.Packet(encoded_packet='6{"a":"0123456789-"}')
assert pkt.data["a"] == "0123456789-"
assert pkt.attachment_count == 0

def test_data_is_binary_list(self):
pkt = packet.Packet()
Expand Down

0 comments on commit f4e1010

Please sign in to comment.