← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/bugzilla-comment-encoding-oops into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/bugzilla-comment-encoding-oops into lp:launchpad.

Commit message:
Force URLs to UTF-8 in externalbugtracker's xmlrpc UrlLib2Transport.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/bugzilla-comment-encoding-oops/+merge/264386

Force URLs to UTF-8 in externalbugtracker's xmlrpc UrlLib2Transport.

Python's httplib doesn't like Unicode paths with non-ASCII bodies.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/bugzilla-comment-encoding-oops into lp:launchpad.
=== modified file 'lib/lp/bugs/externalbugtracker/tests/test_xmlrpc.py'
--- lib/lp/bugs/externalbugtracker/tests/test_xmlrpc.py	2011-02-08 21:01:56 +0000
+++ lib/lp/bugs/externalbugtracker/tests/test_xmlrpc.py	2015-07-10 07:55:43 +0000
@@ -5,6 +5,7 @@
 
 __metaclass__ = type
 
+from urllib2 import URLError
 from xml.parsers.expat import ExpatError
 
 from lp.bugs.externalbugtracker.xmlrpc import UrlLib2Transport
@@ -33,3 +34,13 @@
         self.assertRaises(
             ExpatError, transport.request,
             'www.example.com', 'xmlrpc', "<methodCall />")
+
+    def test_unicode_url(self):
+        # Python's httplib doesn't like Unicode URLs much. Ensure that
+        # they don't cause it to crash, and we get a post-serialisation
+        # connection error instead.
+        transport = UrlLib2Transport(u"http://test.invalid/";)
+        self.assertRaisesWithContent(
+            URLError, '<urlopen error [Errno -2] Name or service not known>',
+            transport.request, u"test.invalid", u"xmlrpc",
+            u"\N{SNOWMAN}".encode('utf-8'))

=== modified file 'lib/lp/bugs/externalbugtracker/xmlrpc.py'
--- lib/lp/bugs/externalbugtracker/xmlrpc.py	2014-08-29 02:04:20 +0000
+++ lib/lp/bugs/externalbugtracker/xmlrpc.py	2015-07-10 07:55:43 +0000
@@ -108,6 +108,10 @@
         Uses the configured proxy server to make the connection.
         """
         url = urlunparse((self.scheme, host, handler, '', '', ''))
+        # httplib can raise a UnicodeDecodeError when using a Unicode
+        # URL, a non-ASCII body and a proxy. http://bugs.python.org/issue12398
+        if isinstance(url, unicode):
+            url = url.encode('utf-8')
         headers = {'Content-type': 'text/xml'}
         request = Request(url, request_body, headers)
         try:


Follow ups