Ticket #5780: unbound_local_error.patch

File unbound_local_error.patch, 1.7 KB (added by j2a, 4 years ago)

Fix for UnboundLocalError and test for it

  • twisted/words/test/test_irc_service.py

     
    4141        self.assertEqual(":example.com foo mynick\r\n",
    4242                          self.stringTransport.value())
    4343
     44    def test_utf8Messages(self):
     45        """
     46        Set utf-8 nick and try to send utf-8 message
     47        """
     48        self.ircUser.irc_NICK("", ["\xd0\xbd\xd0\xb8\xd0\xba"])
     49        self.stringTransport.clear()
     50        self.ircUser.sendMessage("\xd1\x82\xd0\xb5\xd1\x81\xd1\x82")
     51        self.assertEqual(
     52            ":example.com \xd1\x82\xd0\xb5\xd1\x81\xd1\x82 \xd0\xbd\xd0\xb8\xd0\xba\r\n",
     53            self.stringTransport.value())
    4454
     55    def test_wrongUtf8Nick(self):
     56        """
     57        Send message in non-utf8 encoding
     58        """
     59        self.ircUser.irc_NICK("", ["\xd4\xc5\xd3\xd4"])
     60        self.assertEqual(':NickServ!NickServ@services PRIVMSG \xd4\xc5\xd3\xd4 :Your nickname is cannot be decoded.  Please use ASCII or UTF-8.\r\n',
     61                         self.stringTransport.value())
     62
    4563    def response(self):
    4664        """
    4765        Grabs our responses and then clears the transport
  • twisted/words/service.py

     
    290290        [REQUIRED]
    291291        """
    292292        try:
    293             nickname = params[0].decode(self.encoding)
     293            nickname = params[0]
     294            nickname = nickname.decode(self.encoding)
    294295        except UnicodeDecodeError:
    295296            self.privmsg(
    296297                NICKSERV,