Skip to content

Commit 030a713

Browse files
authored
Allow / character in username,password fields in _PROXY envvars. (#23973)
1 parent c1af128 commit 030a713

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
@@ -1851,9 +1851,17 @@ def test_parse_proxy(self):
18511851
('ftp', 'joe', 'password', 'proxy.example.com')),
18521852
# Test for no trailing '/' case
18531853
('http://joe:[email protected]',
1854-
('http', 'joe', 'password', 'proxy.example.com'))
1854+
('http', 'joe', 'password', 'proxy.example.com')),
1855+
# Testcases with '/' character in username, password
1856+
('http://user/name:password@localhost:22',
1857+
('http', 'user/name', 'password', 'localhost:22')),
1858+
('http://username:pass/word@localhost:22',
1859+
('http', 'username', 'pass/word', 'localhost:22')),
1860+
('http://user/name:pass/word@localhost:22',
1861+
('http', 'user/name', 'pass/word', 'localhost:22')),
18551862
]
18561863

1864+
18571865
for tc, expected in parse_proxy_test_cases:
18581866
self.assertEqual(_parse_proxy(tc), expected)
18591867

Lib/urllib/request.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,11 @@ def _parse_proxy(proxy):
773773
raise ValueError("proxy URL with no authority: %r" % proxy)
774774
# We have an authority, so for RFC 3986-compliant URLs (by ss 3.
775775
# and 3.3.), path is empty or starts with '/'
776-
end = r_scheme.find("/", 2)
776+
if '@' in r_scheme:
777+
host_separator = r_scheme.find('@')
778+
end = r_scheme.find("/", host_separator)
779+
else:
780+
end = r_scheme.find("/", 2)
777781
if end == -1:
778782
end = None
779783
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)