@@ -253,14 +253,36 @@ def test_proxy_bypass_environment_host_match(self):
253253 self .assertTrue (bypass ('localhost' ))
254254 self .assertTrue (bypass ('LocalHost' )) # MixedCase
255255 self .assertTrue (bypass ('LOCALHOST' )) # UPPERCASE
256+ self .assertTrue (bypass ('.localhost' ))
256257 self .assertTrue (bypass ('newdomain.com:1234' ))
258+ self .assertTrue (bypass ('.newdomain.com:1234' ))
257259 self .assertTrue (bypass ('foo.d.o.t' )) # issue 29142
260+ self .assertTrue (bypass ('d.o.t' ))
258261 self .assertTrue (bypass ('anotherdomain.com:8888' ))
262+ self .assertTrue (bypass ('.anotherdomain.com:8888' ))
259263 self .assertTrue (bypass ('www.newdomain.com:1234' ))
260264 self .assertFalse (bypass ('prelocalhost' ))
261265 self .assertFalse (bypass ('newdomain.com' )) # no port
262266 self .assertFalse (bypass ('newdomain.com:1235' )) # wrong port
263267
268+ def test_proxy_bypass_environment_always_match (self ):
269+ bypass = urllib .request .proxy_bypass_environment
270+ self .env .set ('NO_PROXY' , '*' )
271+ self .assertTrue (bypass ('newdomain.com' ))
272+ self .assertTrue (bypass ('newdomain.com:1234' ))
273+ self .env .set ('NO_PROXY' , '*, anotherdomain.com' )
274+ self .assertTrue (bypass ('anotherdomain.com' ))
275+ self .assertFalse (bypass ('newdomain.com' ))
276+ self .assertFalse (bypass ('newdomain.com:1234' ))
277+
278+ def test_proxy_bypass_environment_newline (self ):
279+ bypass = urllib .request .proxy_bypass_environment
280+ self .env .set ('NO_PROXY' ,
281+ 'localhost, anotherdomain.com, newdomain.com:1234' )
282+ self .assertFalse (bypass ('localhost\n ' ))
283+ self .assertFalse (bypass ('anotherdomain.com:8888\n ' ))
284+ self .assertFalse (bypass ('newdomain.com:1234\n ' ))
285+
264286
265287class ProxyTests_withOrderedEnv (unittest .TestCase ):
266288
0 commit comments