File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -231,6 +231,19 @@ def test_getproxies_environment_keep_no_proxies(self):
231231 self .assertTrue (urllib .request .proxy_bypass_environment ('anotherdomain.com:8888' ))
232232 self .assertTrue (urllib .request .proxy_bypass_environment ('newdomain.com:1234' ))
233233
234+ def test_proxy_bypass_environment_host_match (self ):
235+ bypass = urllib .request .proxy_bypass_environment
236+ self .env .set ('NO_PROXY' ,
237+ 'localhost, anotherdomain.com, newdomain.com:1234' )
238+ self .assertTrue (bypass ('localhost' ))
239+ self .assertTrue (bypass ('LocalHost' )) # MixedCase
240+ self .assertTrue (bypass ('LOCALHOST' )) # UPPERCASE
241+ self .assertTrue (bypass ('newdomain.com:1234' ))
242+ self .assertTrue (bypass ('anotherdomain.com:8888' ))
243+ self .assertTrue (bypass ('www.newdomain.com:1234' ))
244+ self .assertFalse (bypass ('prelocalhost' ))
245+ self .assertFalse (bypass ('newdomain.com' )) # no port
246+ self .assertFalse (bypass ('newdomain.com:1235' )) # wrong port
234247
235248class ProxyTests_withOrderedEnv (unittest .TestCase ):
236249
Original file line number Diff line number Diff line change @@ -2432,8 +2432,12 @@ def proxy_bypass_environment(host, proxies=None):
24322432 # check if the host ends with any of the DNS suffixes
24332433 no_proxy_list = [proxy .strip () for proxy in no_proxy .split (',' )]
24342434 for name in no_proxy_list :
2435- if name and (hostonly .endswith (name ) or host .endswith (name )):
2436- return 1
2435+ if name :
2436+ name = re .escape (name )
2437+ pattern = r'(.+\.)?%s$' % name
2438+ if (re .match (pattern , hostonly , re .I )
2439+ or re .match (pattern , host , re .I )):
2440+ return 1
24372441 # otherwise, don't bypass
24382442 return 0
24392443
Original file line number Diff line number Diff line change @@ -107,6 +107,11 @@ Core and Builtins
107107Library
108108-------
109109
110+ - Issue #26864: In urllib.request, change the proxy bypass host checking
111+ against no_proxy to be case-insensitive, and to not match unrelated host
112+ names that happen to have a bypassed hostname as a suffix. Patch by Xiang
113+ Zhang.
114+
110115- Issue #26634: recursive_repr() now sets __qualname__ of wrapper. Patch by
111116 Xiang Zhang.
112117
You can’t perform that action at this time.
0 commit comments