Commits

Anonymous committed de51c7f

[svn r6070] XmlRpcPlugin: Fix encoding issue + tests (recently introduced bug).

  • Participants
  • Parent commits 7d58361

Comments (0)

Files changed (2)

trunk/tracrpc/tests/xml.py

             self.assertTrue("listMethods() takes exactly 2 arguments" \
                                     in e.faultString)
 
+    def test_content_encoding(self):
+        test_string = "øæåØÆÅàéüoö"
+        # No encoding / encoding error
+        self.assertRaises(xmlrpclib.ProtocolError, 
+                self.admin.ticket.create, test_string, test_string[::-1], {})
+        # Unicode version (encodable)
+        from trac.util.text import to_unicode
+        test_string = to_unicode(test_string)
+        t_id = self.admin.ticket.create(test_string, test_string[::-1], {})
+        self.assertTrue(t_id > 0)
+        result = self.admin.ticket.get(t_id)
+        self.assertEquals(result[0], t_id)
+        self.assertEquals(result[3]['summary'], test_string)
+        self.assertEquals(result[3]['description'], test_string[::-1])
+        self.assertEquals(unicode, type(result[3]['summary']))
+        self.admin.ticket.delete(t_id)
+
 def suite():
     return unittest.makeSuite(RpcXmlTestCase)
 

trunk/tracrpc/web_ui.py

             return True
 
     def _send_response(self, req, response, content_type='application/xml'):
+        response = to_unicode(response).encode("utf-8")
         req.send_response(200)
         req.send_header('Content-Type', content_type)
-        req.send_header('Content-Length', len(response.encode("utf-8")))
+        req.send_header('Content-Length', len(response))
         req.end_headers()
         req.write(response)