From f55601c91eb7f6e2233c25583bc3ff92e713fa56 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Thu, 26 Feb 2015 13:52:35 -0500 Subject: Make sure URLs are ascii when building HTTP request If an URL ends up with a unicode type, then that will force the body of the HTTP request to unicode; adding the raw bytes of the commit can then cause an encoding error. https://bugzilla.gnome.org/show_bug.cgi?id=745186 --- git-bz | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/git-bz b/git-bz index 7796178..f5559c0 100755 --- a/git-bz +++ b/git-bz @@ -941,6 +941,14 @@ class PermanentRedirector(urllib2.HTTPRedirectHandler): self.current = None return result +def _encode_quoted(m): + return urllib.quote(m.group(0).encode('UTF-8')) + +# Encodes non-ASCII characters as UTF-8 with %-escapes, but doesn't +# change existing escapes in the URL +def encode_utf8(url): + return str(re.sub('[^\x01-\x7f]+', _encode_quoted, url)) + class BugServer(object): def __init__(self, host, path, https, auth_user=None, auth_password=None): self.host = host @@ -970,7 +978,7 @@ class BugServer(object): if self.path: url = self.path + url - uri = "%s://%s%s" % ("https" if self.https else "http", self.host, url); + uri = "%s://%s%s" % ("https" if self.https else "http", self.host.encode("idna"), encode_utf8(url)) req = urllib2.Request(uri, data, headers) response = None -- cgit