浏览代码

bin/darkirc/irc/client: fix bug with split and join of raw IRC message in process_client resulting in replacement of multiple whitespace chars with one whitespace char in PRIVMSG message text part. this solution splits the messages into predefined parts thus keeping the message part of the PRIVMSG message as whole

oars 1 年之前
父节点
当前提交
01f2cd1173
共有 1 个文件被更改,包括 9 次插入9 次删除
  1. 9 9
      bin/darkirc/src/irc/client.rs

+ 9 - 9
bin/darkirc/src/irc/client.rs

@@ -433,15 +433,15 @@ impl Client {
 
 
         // Prefix the message part of PRIVMSG with ':' if is not already.
         // Prefix the message part of PRIVMSG with ':' if is not already.
         // Or realname part of USER command.
         // Or realname part of USER command.
-        let mut words: Vec<String> = line.split_whitespace().map(|s| s.to_string()).collect();
-        if words[0].to_uppercase() == "PRIVMSG" {
-            if words.len() > 1 && !words[2].starts_with(':') {
-                words[2] = format!(":{}", words[2]);
-            }
-            line = words.join(" ");
-        } else if words[0].to_uppercase() == "USER" {
-            if words.len() > 1 && !words[4].starts_with(':') {
-                words[4] = format!(":{}", words[4]);
+        if let Some(index) = match line.split_whitespace().next() {
+            Some("PRIVMSG") => Some(2),
+            Some("USER") => Some(4),
+            _ => None,
+        } {
+            let mut words: Vec<String> =
+                line.splitn(index + 1, char::is_whitespace).map(|s| s.to_string()).collect();
+            if words.len() > index && !words[index].starts_with(':') {
+                words[index] = format!(":{}", words[index]);
             }
             }
             line = words.join(" ");
             line = words.join(" ");
         }
         }