Skip to content
Myr

Merge pull request #1768 from Lukasa/credpct

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Unencode usernames and passwords taken from URLs.

authored by Kenneth Reitz · committed by Kenneth Reitz · parents b2cee7b, e2961b9 · Browse files · 2 files+15 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+15 added−2 removed

  • other:+15 added−2 removed

2 files+15 added−2 removed

modified:requests/utils.py+3 added-2 removed
19 unmodified lines
2021from . import __version__22from . import certs23from .compat import parse_http_list as _parse_list_header24from .compat import (quote, urlparse, bytes, str, OrderedDict, urlunparse,25 is_py2, is_py3, builtin_str, getproxies, proxy_bypass)24from .compat import (quote, urlparse, bytes, str, OrderedDict, unquote, is_py2,25 builtin_str, getproxies, proxy_bypass)26from .cookies import RequestsCookieJar, cookiejar_from_dict27from .structures import CaseInsensitiveDict28from .exceptions import MissingSchema, InvalidURL29
527 unmodified lines
557def get_auth_from_url(url):558 """Given a url with authentication components, extract them into a tuple of559 username,password."""560 if url:561 url = unquote(url)562 parsed = urlparse(url)563 return (parsed.username, parsed.password)564 else:565 return ('', '')
19 unmodified lines
modified:test_requests.py+12 added
596 unmodified lines
597 def test_get_auth_from_url(self):598 url = 'http://user:pass@complex.url.com/path?query=yes'599 assert ('user', 'pass') == requests.utils.get_auth_from_url(url)600601 def test_get_auth_from_url_encoded_spaces(self):602 url = 'http://user:pass%20pass@complex.url.com/path?query=yes'603 assert ('user', 'pass pass') == requests.utils.get_auth_from_url(url)604605 def test_get_auth_from_url_not_encoded_spaces(self):606 url = 'http://user:pass pass@complex.url.com/path?query=yes'607 assert ('user', 'pass pass') == requests.utils.get_auth_from_url(url)608609 def test_get_auth_from_url_percent_chars(self):610 url = 'http://user%user:pass@complex.url.com/path?query=yes'611 assert ('user%user', 'pass') == requests.utils.get_auth_from_url(url)612613 def test_cannot_send_unprepared_requests(self):614 r = requests.Request(url=HTTPBIN)615 with pytest.raises(ValueError):616 requests.Session().send(r)
345 unmodified lines