aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar JustAnotherArchivist2021-04-28 04:57:37 +0000
committerGravatar JustAnotherArchivist2021-04-28 04:57:37 +0000
commit899cc26dd33e39af1fc5cac591572dc934ff2dac (patch)
treedbdc60ef32d9c0af4583b30a642de00494276b83
parentFix memory leak due to asyncio tasks not being cancelled (cf. irclog commit 5... (diff)
signature
Fix crash if the data is split between CR and LF (cf. irclog commit 68c577bc)
-rw-r--r--http2irc.py7
1 files changed, 3 insertions, 4 deletions
diff --git a/http2irc.py b/http2irc.py
index 4a125a0..e8c8c4c 100644
--- a/http2irc.py
+++ b/http2irc.py
@@ -495,13 +495,12 @@ class IRCClientProtocol(asyncio.Protocol):
def data_received(self, data):
self.logger.debug(f'Data received: {data!r}')
- # Split received data on CRLF. If there's any data left in the buffer, prepend it to the first message and process that.
+ # If there's any data left in the buffer, prepend it to the data. Split on CRLF.
# Then, process all messages except the last one (since data might not end on a CRLF) and keep the remainder in the buffer.
# If data does end with CRLF, all messages will have been processed and the buffer will be empty again.
- messages = data.split(b'\r\n')
if self.buffer:
- self.message_received(self.buffer + messages[0])
- messages = messages[1:]
+ data = self.buffer + data
+ messages = data.split(b'\r\n')
for message in messages[:-1]:
self.message_received(message)
self.buffer = messages[-1]