From b64a71e2fa34557011f6eb52ea323da56173e540 Mon Sep 17 00:00:00 2001 From: Maxime Augier Date: Tue, 4 May 2021 19:35:36 +0200 Subject: [PATCH 1/2] Add tests for messages with a leading colon in the suffix --- irc-proto/src/message.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/irc-proto/src/message.rs b/irc-proto/src/message.rs index 82ab7cc..6ef9d8f 100644 --- a/irc-proto/src/message.rs +++ b/irc-proto/src/message.rs @@ -547,4 +547,29 @@ mod test { let message = "@tag=\\:\\s\\\\\\r\\na :test PRIVMSG #test test\r\n"; assert_eq!(msg, message); } + + #[test] + fn to_message_with_colon_in_suffix() { + let msg = "PRIVMSG #test ::test" + .parse::() + .unwrap(); + let message = Message { + tags: None, + prefix: None, + command: PRIVMSG("#test".to_string(), ":test".to_string()) + }; + assert_eq!(msg, message); + } + + #[test] + fn to_string_with_colon_in_suffix() { + let msg = Message { + tags: None, + prefix: None, + command: PRIVMSG("#test".to_string(), ":test".to_string()), + } + .to_string(); + let message = "PRIVMSG #test ::test\r\n"; + assert_eq!(msg, message); + } } From 1e6824a1a58213ea7264c2d1864ec5f9b3bdeda9 Mon Sep 17 00:00:00 2001 From: Maxime Augier Date: Tue, 4 May 2021 19:37:03 +0200 Subject: [PATCH 2/2] Fix incorrect stringification of suffix with leading colon --- irc-proto/src/command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/irc-proto/src/command.rs b/irc-proto/src/command.rs index 49c4a70..669d71f 100644 --- a/irc-proto/src/command.rs +++ b/irc-proto/src/command.rs @@ -209,7 +209,7 @@ fn stringify(cmd: &str, args: &[&str]) -> String { Some((suffix, args)) => { let args = args.join(" "); let sp = if args.is_empty() { "" } else { " " }; - let co = if suffix.is_empty() || suffix.contains(' ') { + let co = if suffix.is_empty() || suffix.contains(' ') || suffix.starts_with(':') { ":" } else { ""