From bcde6ca3937319b2b46107d8dd71c5441dfb4334 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Fri, 2 Jul 2010 21:37:59 +0200 Subject: [PATCH] Fix credentials-with-space bug (bug 1065) Spaces in username or password for HTTP auth were quoted in a wrong way (quote_plus), which made the rest of the code not decode the URL correctly. This patch makes quoting of spaces work correctly and produce URLs that have correct semantics. Unit tests were also added to verify this special case. --- src/gpodder/util.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/gpodder/util.py b/src/gpodder/util.py index e28f6256..5f39b6f8 100644 --- a/src/gpodder/util.py +++ b/src/gpodder/util.py @@ -213,6 +213,8 @@ def username_password_from_url(url): ('i/o', 'P@ss:') >>> username_password_from_url('ftp://%C3%B6sterreich@host.com/') ('\xc3\xb6sterreich', None) + >>> username_password_from_url('http://w%20x:y%20z@example.org/') + ('w x', 'y z') """ if type(url) not in (str, unicode): raise ValueError('URL has to be a string or unicode object.') @@ -836,14 +838,16 @@ def url_add_authentication(url, username, password): 'http://c:d@x.org/' >>> url_add_authentication('http://i%2F:P%40%3A@cx.lan', 'P@:', 'i/') 'http://P%40%3A:i%2F@cx.lan' + >>> url_add_authentication('http://x.org/', 'a b', 'c d') + 'http://a%20b:c%20d@x.org/' """ if username is None or username == '': return url - username = urllib.quote_plus(username) + username = urllib.quote(username, safe='') if password is not None: - password = urllib.quote_plus(password) + password = urllib.quote(password, safe='') auth_string = ':'.join((username, password)) else: auth_string = username -- 2.11.4.GIT