]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Allow / character in username,password fields in _PROXY envvars. (GH-23973)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 29 Dec 2020 12:46:05 +0000 (04:46 -0800)
committerGitHub <noreply@github.com>
Tue, 29 Dec 2020 12:46:05 +0000 (04:46 -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 b71be549d28b5aa9f46a96aa2babf418dd3e3148..12c3f4dbd5bf087764e211523ff88f00ba46704c 100644 (file)
@@ -1849,9 +1849,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 a8c870b9778eba34b1c5b1d7524252a7ee5e8d8c..57d991465a5b0c128a9e885fac389ea3576e4d67 100644 (file)
@@ -771,7 +771,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.