]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Allow / character in username,password fields in _PROXY envvars. (GH-23973) (#23992)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 29 Dec 2020 13:15:14 +0000 (05:15 -0800)
committerGitHub <noreply@github.com>
Tue, 29 Dec 2020 13:15:14 +0000 (05:15 -0800)
(cherry picked from commit 030a713183084594659aefd77b76fe30178e23c8)

Co-authored-by: Senthil Kumaran <senthil@uthcode.com>
Lib/test/test_urllib2.py
Lib/urllib/request.py
Misc/NEWS.d/next/Library/2020-12-27-18-47-01.bpo-23328._xqepZ.rst [new file with mode: 0644]

index 0132059fdb0ad31cd0be71861c981580f91a1c16..160315394094fa51c7337473e34d446ec87f3faa 100644 (file)
@@ -1846,9 +1846,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)
 
index afd634159fa82cd43db13bcca0a4a351899cba4c..550a2732697d94424399b51b269e1fbd9f2939b0 100644 (file)
@@ -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 (file)
index 0000000..07b15d3
--- /dev/null
@@ -0,0 +1 @@
+Allow / character in username, password fields on _PROXY envars.