Skip to content

Commit df79440

Browse files
Allow / character in username,password fields in _PROXY envvars. (GH-23973)
(cherry picked from commit 030a713) Co-authored-by: Senthil Kumaran <[email protected]>
1 parent 1ceb097 commit df79440

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Lib/test/test_urllib2.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1849,9 +1849,17 @@ def test_parse_proxy(self):
18491849
('ftp', 'joe', 'password', 'proxy.example.com')),
18501850
# Test for no trailing '/' case
18511851
('http://joe:[email protected]',
1852-
('http', 'joe', 'password', 'proxy.example.com'))
1852+
('http', 'joe', 'password', 'proxy.example.com')),
1853+
# Testcases with '/' character in username, password
1854+
('http://user/name:password@localhost:22',
1855+
('http', 'user/name', 'password', 'localhost:22')),
1856+
('http://username:pass/word@localhost:22',
1857+
('http', 'username', 'pass/word', 'localhost:22')),
1858+
('http://user/name:pass/word@localhost:22',
1859+
('http', 'user/name', 'pass/word', 'localhost:22')),
18531860
]
18541861

1862+
18551863
for tc, expected in parse_proxy_test_cases:
18561864
self.assertEqual(_parse_proxy(tc), expected)
18571865

Lib/urllib/request.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,11 @@ def _parse_proxy(proxy):
771771
raise ValueError("proxy URL with no authority: %r" % proxy)
772772
# We have an authority, so for RFC 3986-compliant URLs (by ss 3.
773773
# and 3.3.), path is empty or starts with '/'
774-
end = r_scheme.find("/", 2)
774+
if '@' in r_scheme:
775+
host_separator = r_scheme.find('@')
776+
end = r_scheme.find("/", host_separator)
777+
else:
778+
end = r_scheme.find("/", 2)
775779
if end == -1:
776780
end = None
777781
authority = r_scheme[2:end]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow / character in username, password fields on _PROXY envars.

0 commit comments

Comments
 (0)