From: Senthil Kumaran Date: Tue, 29 Dec 2020 12:18:42 +0000 (-0800) Subject: Allow / character in username,password fields in _PROXY envvars. (#23973) X-Git-Tag: v3.10.0a4~48 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=030a713183084594659aefd77b76fe30178e23c8;p=thirdparty%2FPython%2Fcpython.git Allow / character in username,password fields in _PROXY envvars. (#23973) --- diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 12ad6ae79d5b..9db23e6ce04b 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1851,9 +1851,17 @@ class MiscTests(unittest.TestCase): ('ftp', 'joe', 'password', 'proxy.example.com')), # Test for no trailing '/' case ('http://joe:password@proxy.example.com', - ('http', 'joe', 'password', 'proxy.example.com')) + ('http', 'joe', 'password', 'proxy.example.com')), + # Testcases with '/' character in username, password + ('http://user/name:password@localhost:22', + ('http', 'user/name', 'password', 'localhost:22')), + ('http://username:pass/word@localhost:22', + ('http', 'username', 'pass/word', 'localhost:22')), + ('http://user/name:pass/word@localhost:22', + ('http', 'user/name', 'pass/word', 'localhost:22')), ] + for tc, expected in parse_proxy_test_cases: self.assertEqual(_parse_proxy(tc), expected) diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 39974d975ee1..e5febe61f556 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -773,7 +773,11 @@ def _parse_proxy(proxy): raise ValueError("proxy URL with no authority: %r" % proxy) # We have an authority, so for RFC 3986-compliant URLs (by ss 3. # and 3.3.), path is empty or starts with '/' - end = r_scheme.find("/", 2) + if '@' in r_scheme: + host_separator = r_scheme.find('@') + end = r_scheme.find("/", host_separator) + else: + end = r_scheme.find("/", 2) if end == -1: end = None authority = r_scheme[2:end] diff --git a/Misc/NEWS.d/next/Library/2020-12-27-18-47-01.bpo-23328._xqepZ.rst b/Misc/NEWS.d/next/Library/2020-12-27-18-47-01.bpo-23328._xqepZ.rst new file mode 100644 index 000000000000..07b15d34e8d5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-12-27-18-47-01.bpo-23328._xqepZ.rst @@ -0,0 +1 @@ +Allow / character in username, password fields on _PROXY envars.