@@ -261,14 +261,36 @@ def test_proxy_bypass_environment_host_match(self):
261261 self .assertTrue (bypass ('localhost' ))
262262 self .assertTrue (bypass ('LocalHost' )) # MixedCase
263263 self .assertTrue (bypass ('LOCALHOST' )) # UPPERCASE
264+ self .assertTrue (bypass ('.localhost' ))
264265 self .assertTrue (bypass ('newdomain.com:1234' ))
266+ self .assertTrue (bypass ('.newdomain.com:1234' ))
265267 self .assertTrue (bypass ('foo.d.o.t' )) # issue 29142
268+ self .assertTrue (bypass ('d.o.t' ))
266269 self .assertTrue (bypass ('anotherdomain.com:8888' ))
270+ self .assertTrue (bypass ('.anotherdomain.com:8888' ))
267271 self .assertTrue (bypass ('www.newdomain.com:1234' ))
268272 self .assertFalse (bypass ('prelocalhost' ))
269273 self .assertFalse (bypass ('newdomain.com' )) # no port
270274 self .assertFalse (bypass ('newdomain.com:1235' )) # wrong port
271275
276+ def test_proxy_bypass_environment_always_match (self ):
277+ bypass = urllib .request .proxy_bypass_environment
278+ self .env .set ('NO_PROXY' , '*' )
279+ self .assertTrue (bypass ('newdomain.com' ))
280+ self .assertTrue (bypass ('newdomain.com:1234' ))
281+ self .env .set ('NO_PROXY' , '*, anotherdomain.com' )
282+ self .assertTrue (bypass ('anotherdomain.com' ))
283+ self .assertFalse (bypass ('newdomain.com' ))
284+ self .assertFalse (bypass ('newdomain.com:1234' ))
285+
286+ def test_proxy_bypass_environment_newline (self ):
287+ bypass = urllib .request .proxy_bypass_environment
288+ self .env .set ('NO_PROXY' ,
289+ 'localhost, anotherdomain.com, newdomain.com:1234' )
290+ self .assertFalse (bypass ('localhost\n ' ))
291+ self .assertFalse (bypass ('anotherdomain.com:8888\n ' ))
292+ self .assertFalse (bypass ('newdomain.com:1234\n ' ))
293+
272294
273295class ProxyTests_withOrderedEnv (unittest .TestCase ):
274296
0 commit comments