Bug 810330 - Port Bio 1772 - IRC account disconnects on receiving action messages containing line breaks, r=aleth,a=Standard8.
authorPatrick Cloke <clokep@gmail.com>
Tue, 06 Nov 2012 16:51:17 -0500
changeset 13551 161c4dc3487c2b686500b0f6e2cb582f563a3e61
parent 13550 82fcebdc15e2eeeb6e34f4cf0fc3da8dc4c1a958
child 13552 6ac7d8c3e2f02eaa6ac2f1dd2b804b4945f83c7a
push id3
push userbugzilla@standard8.plus.com
push dateFri, 16 Nov 2012 10:54:06 +0000
reviewersaleth, Standard8
bugs810330
Bug 810330 - Port Bio 1772 - IRC account disconnects on receiving action messages containing line breaks, r=aleth,a=Standard8.
chat/protocols/irc/irc.js
chat/protocols/irc/test/test_ircMessage.js
--- a/chat/protocols/irc/irc.js
+++ b/chat/protocols/irc/irc.js
@@ -43,17 +43,17 @@ function ircMessage(aData) {
   //     <last parameter>: /.+/
   // See http://joshualuckers.nl/2010/01/10/regular-expression-to-match-raw-irc-messages/
   // Note that this expression is slightly more aggressive in matching than RFC
   // 2812 would allow. It allows for empty parameters (besides the last
   // parameter, which can always be empty), by allowing two spaces in a row.
   // (This is for compatibility with Unreal's 432 response, which returns an
   // empty first parameter.) It also allows a trailing space after the
   // <parameter>s when no <last parameter> is present (also occurs with Unreal).
-  if (!(temp = aData.match(/^(?::([^ ]+) )?([^ ]+)((?: +[^: ][^ ]*)*)? ?(?::(.*))?$/))) {
+  if (!(temp = aData.match(/^(?::([^ ]+) )?([^ ]+)((?: +[^: ][^ ]*)*)? ?(?::([\s\S]*))?$/))) {
     ERROR("Couldn't parse message: \"" + aData + "\"");
     return message;
   }
 
   // Assume message is from the server if not specified
   prefix = temp[1];
   message.command = temp[2];
   // Space separated parameters. Since we expect a space as the first thing
--- a/chat/protocols/irc/test/test_ircMessage.js
+++ b/chat/protocols/irc/test/test_ircMessage.js
@@ -114,16 +114,17 @@ const testData = [
   "PRIVMSG foo :This is a test.", // Test sending a space.
   "PRIVMSG foo :", // Empty last parameter.
   "PRIVMSG foo :This is :a test." // A "second" last parameter.
 ];
 
 function run_test() {
   add_test(testRFC2812Messages);
   add_test(testBrokenUnrealMessages);
+  add_test(testNewLinesInMessages);
 
   run_next_test();
 }
 
 function testRFC2812Messages() {
   for each (let expectedStringMessage in testData) {
     let message = irc.ircMessage(expectedStringMessage);
 
@@ -169,16 +170,46 @@ function testBrokenUnrealMessages() {
       params: ["", "#momo", "Erroneous Nickname: Illegal characters"],
       servername: "gravel.mozilla.org"
     },
     ":gravel.mozilla.org MODE #tckk +n ":  {
       rawMessage: ":gravel.mozilla.org MODE #tckk +n ",
       command: "MODE",
       params: ["#tckk", "+n"],
       servername: "gravel.mozilla.org"
-    },
+    }
   };
 
   for (let messageStr in messages)
     do_check_true(isEqual(messages[messageStr], irc.ircMessage(messageStr)));
 
   run_next_test();
 }
+
+// After unescaping we can end up with line breaks inside of IRC messages. Test
+// this edge case specifically.
+function testNewLinesInMessages() {
+  let messages = {
+    ":test!Instantbir@host PRIVMSG #instantbird :First line\nSecond line": {
+      rawMessage: ":test!Instantbir@host PRIVMSG #instantbird :First line\nSecond line",
+      command: "PRIVMSG",
+      params: ["#instantbird", "First line\nSecond line"],
+      nickname: "test",
+      user: "Instantbir",
+      host: "host",
+      source: "Instantbir@host"
+    },
+    ":test!Instantbir@host PRIVMSG #instantbird :First line\r\nSecond line": {
+      rawMessage: ":test!Instantbir@host PRIVMSG #instantbird :First line\r\nSecond line",
+      command: "PRIVMSG",
+      params: ["#instantbird", "First line\r\nSecond line"],
+      nickname: "test",
+      user: "Instantbir",
+      host: "host",
+      source: "Instantbir@host"
+    }
+  };
+
+  for (let messageStr in messages)
+    do_check_true(isEqual(messages[messageStr], irc.ircMessage(messageStr)));
+
+  run_next_test();
+}