Skip to content

Commit f4e1010

Browse files
Fixed incorrect handling of dashes inside the JSON payload of a packet (Fixes #675)
1 parent 1f0c8c6 commit f4e1010

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

socketio/packet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ def decode(self, encoded_packet):
7979
self.data = None
8080
ep = ep[1:]
8181
dash = ep.find('-')
82-
if dash > 10:
83-
raise ValueError('too many attachments')
8482
attachment_count = 0
8583
if dash > 0 and ep[0:dash].isdigit():
84+
if dash > 10:
85+
raise ValueError('too many attachments')
8686
attachment_count = int(ep[0:dash])
8787
ep = ep[dash + 1:]
8888
if ep and ep[0:1] == '/':

tests/common/test_packet.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,12 @@ def test_decode_too_many_binary_packets(self):
261261

262262
def test_decode_attachment_count_too_long(self):
263263
with pytest.raises(ValueError):
264-
packet.Packet(encoded_packet='6' + ('1' * 11) + '-{"a":"123}')
264+
packet.Packet(encoded_packet='6' + ('1' * 11) + '-{"a":"123"}')
265+
266+
def test_decode_dash_in_payload(self):
267+
pkt = packet.Packet(encoded_packet='6{"a":"0123456789-"}')
268+
assert pkt.data["a"] == "0123456789-"
269+
assert pkt.attachment_count == 0
265270

266271
def test_data_is_binary_list(self):
267272
pkt = packet.Packet()

0 commit comments

Comments
 (0)