From: Cory Benfield Date: Sat, 11 Jan 2014 09:59:23 +0000 (+0000) Subject: Unquote the auth after splitting the url. X-Git-Tag: upstream/2.2.1~6^2~1^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ca187abd13052fee100909076358fca89b473e0f;p=platform%2Fupstream%2Fpython-requests.git Unquote the auth after splitting the url. --- diff --git a/requests/utils.py b/requests/utils.py index 7a4d44d..168ff02 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -635,11 +635,14 @@ def get_auth_from_url(url): """Given a url with authentication components, extract them into a tuple of username,password.""" if url: - url = unquote(url) parsed = urlparse(url) - return (parsed.username, parsed.password) - else: - return ('', '') + + try: + return (unquote(parsed.username), unquote(parsed.password)) + except AttributeError: + pass + + return ('', '') def to_native_string(string, encoding='ascii'): diff --git a/test_requests.py b/test_requests.py index 1e8e723..4c1a369 100755 --- a/test_requests.py +++ b/test_requests.py @@ -194,7 +194,7 @@ class RequestsTestCase(unittest.TestCase): assert r.json()['cookies']['foo'] == 'bar' # Make sure the session cj is still the custom one assert s.cookies is cj - + def test_param_cookiejar_works(self): cj = cookielib.CookieJar() cookiejar_from_dict({'foo' : 'bar'}, cj) @@ -705,6 +705,10 @@ class RequestsTestCase(unittest.TestCase): url = 'http://user%user:pass@complex.url.com/path?query=yes' assert ('user%user', 'pass') == requests.utils.get_auth_from_url(url) + def test_get_auth_from_url_encoded_hashes(self): + url = 'http://user:pass%23pass@complex.url.com/path?query=yes' + assert ('user', 'pass#pass') == requests.utils.get_auth_from_url(url) + def test_cannot_send_unprepared_requests(self): r = requests.Request(url=HTTPBIN) with pytest.raises(ValueError):