[Python-checkins] Allow / character in username, password fields in _PROXY envvars. (GH-23973) (#23992)

orsenthil webhook-mailer at python.org
Tue Dec 29 08:15:28 EST 2020


https://github.com/python/cpython/commit/741f22df24ca61db38b5a7a2a58b5939b7154a01
commit: 741f22df24ca61db38b5a7a2a58b5939b7154a01
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: orsenthil <skumaran at gatech.edu>
date: 2020-12-29T05:15:14-08:00
summary:

Allow / character in username,password fields in _PROXY envvars. (GH-23973) (#23992)

(cherry picked from commit 030a713183084594659aefd77b76fe30178e23c8)

Co-authored-by: Senthil Kumaran <senthil at uthcode.com>

files:
A Misc/NEWS.d/next/Library/2020-12-27-18-47-01.bpo-23328._xqepZ.rst
M Lib/test/test_urllib2.py
M Lib/urllib/request.py

diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 0132059fdb0ad..160315394094f 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -1846,9 +1846,17 @@ def test_parse_proxy(self):
              ('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 afd634159fa82..550a2732697d9 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -779,7 +779,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 0000000000000..07b15d34e8d56
--- /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.



More information about the Python-checkins mailing list