diff options
author | Sergey Shepelev <temotor@gmail.com> | 2018-03-19 22:40:28 +0300 |
---|---|---|
committer | Sergey Shepelev <temotor@gmail.com> | 2018-03-20 22:17:49 +0300 |
commit | 12b26f92e308cbfa593dcf6e1d6c794e40876928 (patch) | |
tree | 7775b87682fcaca45b3d7e285283e3dae295945d | |
parent | ea67159a013e6cd014bc31241b7572e60530a240 (diff) | |
download | platform_external_python_httplib2-12b26f92e308cbfa593dcf6e1d6c794e40876928.tar.gz platform_external_python_httplib2-12b26f92e308cbfa593dcf6e1d6c794e40876928.tar.bz2 platform_external_python_httplib2-12b26f92e308cbfa593dcf6e1d6c794e40876928.zip |
proxy: no_proxy=bar was matching foobar
https://github.com/httplib2/httplib2/issues/94
-rw-r--r-- | python2/httplib2/__init__.py | 15 | ||||
-rw-r--r-- | python3/httplib2/__init__.py | 15 | ||||
-rw-r--r-- | tests/test_proxy.py | 8 |
3 files changed, 24 insertions, 14 deletions
diff --git a/python2/httplib2/__init__.py b/python2/httplib2/__init__.py index 986dc7f..feffacb 100644 --- a/python2/httplib2/__init__.py +++ b/python2/httplib2/__init__.py @@ -838,12 +838,15 @@ class ProxyInfo(object): if self.bypass_hosts is AllHosts: return True - bypass = False - for domain in self.bypass_hosts: - if hostname.endswith(domain): - bypass = True - - return bypass + hostname = '.' + hostname.lstrip('.') + for skip_name in self.bypass_hosts: + # *.suffix + if skip_name.startswith('.') and hostname.endswith(skip_name): + return True + # exact match + if hostname == '.' + skip_name: + return True + return False def proxy_info_from_environment(method='http'): diff --git a/python3/httplib2/__init__.py b/python3/httplib2/__init__.py index 61e69b2..5deee82 100644 --- a/python3/httplib2/__init__.py +++ b/python3/httplib2/__init__.py @@ -795,12 +795,15 @@ class ProxyInfo(object): if self.bypass_hosts is AllHosts: return True - bypass = False - for domain in self.bypass_hosts: - if hostname.endswith(domain): - bypass = True - - return bypass + hostname = '.' + hostname.lstrip('.') + for skip_name in self.bypass_hosts: + # *.suffix + if skip_name.startswith('.') and hostname.endswith(skip_name): + return True + # exact match + if hostname == '.' + skip_name: + return True + return False def proxy_info_from_environment(method='http'): diff --git a/tests/test_proxy.py b/tests/test_proxy.py index d1bdb66..3f1622e 100644 --- a/tests/test_proxy.py +++ b/tests/test_proxy.py @@ -46,11 +46,15 @@ def test_from_env_none(): def test_applies_to(): os.environ['http_proxy'] = 'http://myproxy.example.com:80' os.environ['https_proxy'] = 'http://myproxy.example.com:81' - os.environ['no_proxy'] = 'localhost,otherhost.domain.local,example.com' + os.environ['no_proxy'] = 'localhost,example.com,.wildcard' pi = httplib2.proxy_info_from_environment() assert not pi.applies_to('localhost') assert pi.applies_to('www.google.com') - assert not pi.applies_to('www.example.com') + assert pi.applies_to('prefixlocalhost') + assert pi.applies_to('www.example.com') + assert pi.applies_to('sub.example.com') + assert not pi.applies_to('sub.wildcard') + assert not pi.applies_to('pub.sub.wildcard') def test_noproxy_trailing_comma(): |