]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #29142: Fix suffixes in no_proxy handling in urllib.
authorXiang Zhang <angwerzx@126.com>
Mon, 9 Jan 2017 03:47:55 +0000 (11:47 +0800)
committerXiang Zhang <angwerzx@126.com>
Mon, 9 Jan 2017 03:47:55 +0000 (11:47 +0800)
In urllib.request, suffixes in no_proxy environment variable with
leading dots could match related hostnames again (e.g. .b.c matches a.b.c).
Patch by Milan Oberkirch.

Lib/test/test_urllib.py
Lib/urllib/request.py
Misc/NEWS

index 247598ac570dda28d42d98d576dafd2914c1e80e..1772399803499ad033e166f0a5254ca5f9997b0e 100644 (file)
@@ -247,11 +247,12 @@ class ProxyTests(unittest.TestCase):
     def test_proxy_bypass_environment_host_match(self):
         bypass = urllib.request.proxy_bypass_environment
         self.env.set('NO_PROXY',
-            'localhost, anotherdomain.com, newdomain.com:1234')
+                     'localhost, anotherdomain.com, newdomain.com:1234, .d.o.t')
         self.assertTrue(bypass('localhost'))
         self.assertTrue(bypass('LocalHost'))                 # MixedCase
         self.assertTrue(bypass('LOCALHOST'))                 # UPPERCASE
         self.assertTrue(bypass('newdomain.com:1234'))
+        self.assertTrue(bypass('foo.d.o.t'))                 # issue 29142
         self.assertTrue(bypass('anotherdomain.com:8888'))
         self.assertTrue(bypass('www.newdomain.com:1234'))
         self.assertFalse(bypass('prelocalhost'))
index a4bf97dcd386adf0e52227f12d2a175027d7f5e7..a46c689493575753b8b6bd3f5c5727f6a16cf0bc 100644 (file)
@@ -2450,6 +2450,7 @@ def proxy_bypass_environment(host, proxies=None):
     no_proxy_list = [proxy.strip() for proxy in no_proxy.split(',')]
     for name in no_proxy_list:
         if name:
+            name = name.lstrip('.')  # ignore leading dots
             name = re.escape(name)
             pattern = r'(.+\.)?%s$' % name
             if (re.match(pattern, hostonly, re.I)
index 95535f843f2ed8c8d8af1d1b8e2caf41d665997c..df9d0dd2c2cb270b6f598207993d30c2a34e9b73 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #29142: In urllib.request, suffixes in no_proxy environment variable with
+  leading dots could match related hostnames again (e.g. .b.c matches a.b.c).
+  Patch by Milan Oberkirch.
 
 What's New in Python 3.5.3 release candidate 1?
 ===============================================