Skip to content

Commit 741f22d

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

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
@@ -1846,9 +1846,17 @@ def test_parse_proxy(self):
18461846
('ftp', 'joe', 'password', 'proxy.example.com')),
18471847
# Test for no trailing '/' case
18481848
('http://joe:[email protected]',
1849-
('http', 'joe', 'password', 'proxy.example.com'))
1849+
('http', 'joe', 'password', 'proxy.example.com')),
1850+
# Testcases with '/' character in username, password
1851+
('http://user/name:password@localhost:22',
1852+
('http', 'user/name', 'password', 'localhost:22')),
1853+
('http://username:pass/word@localhost:22',
1854+
('http', 'username', 'pass/word', 'localhost:22')),
1855+
('http://user/name:pass/word@localhost:22',
1856+
('http', 'user/name', 'pass/word', 'localhost:22')),
18501857
]
18511858

1859+
18521860
for tc, expected in parse_proxy_test_cases:
18531861
self.assertEqual(_parse_proxy(tc), expected)
18541862

Lib/urllib/request.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,11 @@ def _parse_proxy(proxy):
779779
raise ValueError("proxy URL with no authority: %r" % proxy)
780780
# We have an authority, so for RFC 3986-compliant URLs (by ss 3.
781781
# and 3.3.), path is empty or starts with '/'
782-
end = r_scheme.find("/", 2)
782+
if '@' in r_scheme:
783+
host_separator = r_scheme.find('@')
784+
end = r_scheme.find("/", host_separator)
785+
else:
786+
end = r_scheme.find("/", 2)
783787
if end == -1:
784788
end = None
785789
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)