Commits

Jason R. Coombs  committed c727d68

Added error checking when sending a message - for both message length and embedded carriage returns. Fixes failing test and fixes #4.

  • Participants
  • Parent commits 8a2c842

Comments (0)

Files changed (2)

+3.0.1
+=====
+
+# Added error checking when sending a message - for both message length and
+  embedded carriage returns. Fixes #4.
+* Updated README.
+
 3.0
 ===
 

File irc/client.py

 
     def privmsg(self, target, text):
         """Send a PRIVMSG command."""
-        # Should limit len(text) here!
         self.send_raw("PRIVMSG %s :%s" % (target, text))
 
     def privmsg_many(self, targets, text):
         """Send a PRIVMSG command to multiple targets."""
-        # Should limit len(text) here!
-        self.send_raw("PRIVMSG %s :%s" % (",".join(targets), text))
+        target = ','.join(targets)
+        return self.privmsg(target, text)
 
     def quit(self, message=""):
         """Send a QUIT command."""
 
         The string will be padded with appropriate CR LF.
         """
+        # The string should not contain any carriage return other than the
+        # one added here.
+        if '\n' in string:
+            raise ValueError("Carriage returns not allowed in privmsg(text)")
         bytes = string.encode('utf-8') + '\r\n'
+        # According to the RFC http://tools.ietf.org/html/rfc2812#page-6,
+        # clients should not transmit more than 512 bytes.
+        if len(bytes) > 512:
+            raise ValueError("Messages limited to 512 bytes")
         sender = self.ssl.write if self.ssl else self.socket.send
         if self.socket is None:
             raise ServerNotConnectedError("Not connected.")