@@ -270,14 +270,36 @@ def test_proxy_bypass_environment_host_match(self):
270270 self .assertTrue (bypass ('localhost' ))
271271 self .assertTrue (bypass ('LocalHost' )) # MixedCase
272272 self .assertTrue (bypass ('LOCALHOST' )) # UPPERCASE
273+ self .assertTrue (bypass ('.localhost' ))
273274 self .assertTrue (bypass ('newdomain.com:1234' ))
275+ self .assertTrue (bypass ('.newdomain.com:1234' ))
274276 self .assertTrue (bypass ('foo.d.o.t' )) # issue 29142
277+ self .assertTrue (bypass ('d.o.t' ))
275278 self .assertTrue (bypass ('anotherdomain.com:8888' ))
279+ self .assertTrue (bypass ('.anotherdomain.com:8888' ))
276280 self .assertTrue (bypass ('www.newdomain.com:1234' ))
277281 self .assertFalse (bypass ('prelocalhost' ))
278282 self .assertFalse (bypass ('newdomain.com' )) # no port
279283 self .assertFalse (bypass ('newdomain.com:1235' )) # wrong port
280284
285+ def test_proxy_bypass_environment_always_match (self ):
286+ bypass = urllib .request .proxy_bypass_environment
287+ self .env .set ('NO_PROXY' , '*' )
288+ self .assertTrue (bypass ('newdomain.com' ))
289+ self .assertTrue (bypass ('newdomain.com:1234' ))
290+ self .env .set ('NO_PROXY' , '*, anotherdomain.com' )
291+ self .assertTrue (bypass ('anotherdomain.com' ))
292+ self .assertFalse (bypass ('newdomain.com' ))
293+ self .assertFalse (bypass ('newdomain.com:1234' ))
294+
295+ def test_proxy_bypass_environment_newline (self ):
296+ bypass = urllib .request .proxy_bypass_environment
297+ self .env .set ('NO_PROXY' ,
298+ 'localhost, anotherdomain.com, newdomain.com:1234' )
299+ self .assertFalse (bypass ('localhost\n ' ))
300+ self .assertFalse (bypass ('anotherdomain.com:8888\n ' ))
301+ self .assertFalse (bypass ('newdomain.com:1234\n ' ))
302+
281303
282304class ProxyTests_withOrderedEnv (unittest .TestCase ):
283305
0 commit comments