Bug 842183 - Land in comm-central Instantbird's changes to chat/ - 5 - Bio 1818 - "Couldn't parse message" due to trailing spaces, r=aleth.
authorPatrick Cloke <clokep@gmail.com>
Thu, 22 Nov 2012 12:40:54 -0500
changeset 14883 25e1726d6df85ec62b0d005b184cea2d96dfd752
parent 14882 daad988db75ff4efbb1e12c4046e52ca00d5eaa1
child 14884 b7b1aefc7fd3889d68c0b3d2dae8f232c0ad06f3
push id867
push userbugzilla@standard8.plus.com
push dateMon, 01 Apr 2013 20:44:27 +0000
treeherdercomm-beta@797726b8d244 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaleth
bugs842183
Bug 842183 - Land in comm-central Instantbird's changes to chat/ - 5 - Bio 1818 - "Couldn't parse message" due to trailing spaces, r=aleth.
chat/protocols/irc/irc.js
chat/protocols/irc/test/test_ircMessage.js
--- a/chat/protocols/irc/irc.js
+++ b/chat/protocols/irc/irc.js
@@ -38,21 +38,21 @@ function ircMessage(aData) {
   //   [":" <prefix> " "] <command> [" " <parameter>]* [":" <last parameter>]
   //     <prefix>: :(<server name> | <nickname> [["!" <user>] "@" <host>])
   //     <command>: /[^ ]+/
   //     <parameter>: /[^ ]+/
   //     <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.
+  // parameter, which can always be empty), by allowing multiple spaces.
   // (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(/^(?::([^ ]+) )?([^ ]+)((?: +[^: ][^ ]*)*)? ?(?::([\s\S]*))?$/))) {
+  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
@@ -165,21 +165,27 @@ function isEqual(aObject1, aObject2) {
 function testBrokenUnrealMessages() {
   let messages = {
     ":gravel.mozilla.org 432  #momo :Erroneous Nickname: Illegal characters": {
       rawMessage: ":gravel.mozilla.org 432  #momo :Erroneous Nickname: Illegal characters",
       command: "432",
       params: ["", "#momo", "Erroneous Nickname: Illegal characters"],
       servername: "gravel.mozilla.org"
     },
-    ":gravel.mozilla.org MODE #tckk +n ":  {
+    ":gravel.mozilla.org MODE #tckk +n ": {
       rawMessage: ":gravel.mozilla.org MODE #tckk +n ",
       command: "MODE",
       params: ["#tckk", "+n"],
       servername: "gravel.mozilla.org"
+    },
+    ":services.esper.net MODE #foo-bar +o foobar  ": {
+      rawMessage: ":services.esper.net MODE #foo-bar +o foobar  ",
+      command: "MODE",
+      params: ["#foo-bar", "+o", "foobar"],
+      servername: "services.esper.net"
     }
   };
 
   for (let messageStr in messages)
     do_check_true(isEqual(messages[messageStr], irc.ircMessage(messageStr)));
 
   run_next_test();
 }