Преглед изворни кода

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.
         // 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(" ");
         }