Skip to content
Myr

Fixed parsing of username and password encoded in the URI

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

authored by Roberto Migli · committed by Roberto Migli · parent ac4e058 · Browse files · 2 files+18 added−3 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+18 added−3 removed

  • other:+18 added−3 removed

2 files+18 added−3 removed

modified:requests/utils.py+8 added-2 removed
633 unmodified lines
634def get_auth_from_url(url):635 """Given a url with authentication components, extract them into a tuple of636 username,password."""637 if url:638 url = unquote(url)638 parsed = urlparse(url)640 return (parsed.username, parsed.password)639 username = ""640 password = ""641642 if parsed.username is not None:643 username = unquote(parsed.username)644 if parsed.password is not None:645 password = unquote(parsed.password)646 return (username, password)647 else:648 return ('', '')649650
17 unmodified lines
modified:test_requests.py+10 added-1 removed
700 unmodified lines
701 url = 'http://user:pass pass@complex.url.com/path?query=yes'702 assert ('user', 'pass pass') == requests.utils.get_auth_from_url(url)703704 def test_get_auth_from_url_percent_chars(self):705 url = 'http://user%user:pass@complex.url.com/path?query=yes'705 url = 'http://user%25user:pass@complex.url.com/path?query=yes'706 assert ('user%user', 'pass') == requests.utils.get_auth_from_url(url)707708 def test_cannot_send_unprepared_requests(self):709 r = requests.Request(url=HTTPBIN)
381 unmodified lines
1091 from requests.utils import address_in_network1092 assert address_in_network('192.168.1.1', '192.168.1.0/24')1093 assert not address_in_network('172.16.0.1', '192.168.1.0/24')10941095 def test_get_auth_from_url(self):1096 from requests.utils import get_auth_from_url1097 from requests.compat import quote1098 percent_encoding_test_chars = "%!*'();:@&=+$,/?#[] "1099 url_address = "request.com/url.html#test"1100 url = "http://" + quote(percent_encoding_test_chars, '') + ':' + quote(percent_encoding_test_chars, '') + '@' + url_address1101 (username, password) = get_auth_from_url(url)1102 assert username == percent_encoding_test_chars1103 assert password == percent_encoding_test_chars110411051106class TestMorselToCookieExpires(unittest.TestCase):1107
58 unmodified lines