irc: Improve the parsing
patch b2ed84c15eb61138a3ed6f39254b54a2e9536345
Author: E. Bosch <presidev@AT@gmail.com>
Date: Wed Feb 17 02:53:21 CET 2021
* irc: Improve the parsing
Recognize commands case insensitive: the RFCs are not very concise about
this and I don't know about clients sending commands in lower case but
just in case and it won't hurt
Line terminator: according RFCs should be \r\n but some clients only
send \n, I was confused about this but the parser must be robust and
now any combination of \r and \n is recognized
diff -rN -u old-irgramd/irc.py new-irgramd/irc.py
--- old-irgramd/irc.py 2024-10-23 06:24:56.084093800 +0200
+++ new-irgramd/irc.py 2024-10-23 06:24:56.088093793 +0200
@@ -23,7 +23,7 @@
# IRC Regular Expressions
-PREFIX = r'(:[^ ]+ +|)'
+PREFIX = r'(?ai)(:[^ ]+ +|)'
IRC_JOIN_RX = re.compile(PREFIX + r'JOIN( +:| +|\n)(?P<channels>[^\n]+|)')
IRC_NAMES_RX = re.compile(PREFIX + r'NAMES( +:| +|\n)(?P<channels>[^\n]+|)')
IRC_NICK_RX = re.compile(PREFIX + r'NICK( +:| +|\n)(?P<nick>[^\n]+|)')
@@ -62,7 +62,7 @@
user.del_from_channels(self)
del user
break
- message = message.decode()
+ message = message.decode().replace('\r','\n')
self.logger.debug(message)
for pattern, handler, register_required in self.irc_handlers: