diff options
author | Owen W. Taylor <otaylor@fishsoup.net> | 2015-02-26 13:52:35 -0500 |
---|---|---|
committer | Owen W. Taylor <otaylor@fishsoup.net> | 2015-02-26 13:58:04 -0500 |
commit | f55601c91eb7f6e2233c25583bc3ff92e713fa56 (patch) | |
tree | 886478ce3ca595f2b366b8df6686a56be9a99673 | |
parent | 7a676905ecdac9d695843b5b5e261dc765e55b35 (diff) | |
download | git-bz-f55601c91eb7f6e2233c25583bc3ff92e713fa56.tar.gz |
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
-rwxr-xr-x | git-bz | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -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 |