Skip to content

Commit

Permalink
Merge pull request #641 from squidowl/fix/parsing
Browse files Browse the repository at this point in the history
Handle addtl. \r from digitalirc
  • Loading branch information
tarkah authored Nov 7, 2024
2 parents 3b9e335 + 8b8d7df commit 71d1c01
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion irc/proto/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ pub fn message_bytes(bytes: Vec<u8>) -> Result<Message, Error> {

/// Parses a single IRC message terminated by '\r\n`
pub fn message(input: &str) -> Result<Message, Error> {
let mut message = cut(terminated(tuple((opt(tags), opt(source), command)), crlf));
let mut message = cut(terminated(
tuple((opt(tags), opt(source), command)),
// Discard addtl. \r if it exists
alt((preceded(char('\r'), crlf), crlf)),
));

message(input)
.finish()
Expand Down Expand Up @@ -259,6 +263,8 @@ mod test {
":test!test@5555:5555:0:55:5555:5555:5555:5555 396 test user/test :is now your visible host\r\n",
":atw.hu.quakenet.org 001 test :Welcome to the QuakeNet IRC Network, test\r\n",
"@time=2023-07-20T21:19:11.000Z :chat!test@user/test/bot/chat PRIVMSG ##chat :\\_o< quack!\r\n",
// Extra \r sent by digitalirc
"@batch=JQlhpjWY7SYaBPQtXAfUQh;msgid=UGnor4DBoafs6ge0UgsHF7-aVdnYMbjbdTf9eEHQmPKWA;time=2024-11-07T12:04:28.361Z :[email protected] JOIN #pixelcove * :foo\r\r\n",
];

for test in tests {
Expand Down

0 comments on commit 71d1c01

Please sign in to comment.