diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-01-05 12:14:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-05 12:14:31 (GMT) |
commit | 6a265f0d0c0a4b3b8fecf4275d49187a384167f4 (patch) | |
tree | 238eefb63cc4523147fcd84151954f37ffbfd15a /Lib/urllib/request.py | |
parent | ec007cb43faf5f33d06efbc28152c7fdcb2edb9c (diff) | |
download | cpython-6a265f0d0c0a4b3b8fecf4275d49187a384167f4.zip cpython-6a265f0d0c0a4b3b8fecf4275d49187a384167f4.tar.gz cpython-6a265f0d0c0a4b3b8fecf4275d49187a384167f4.tar.bz2 |
bpo-39057: Fix urllib.request.proxy_bypass_environment(). (GH-17619)
Ignore leading dots and no longer ignore a trailing newline.
Diffstat (limited to 'Lib/urllib/request.py')
-rw-r--r-- | Lib/urllib/request.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 39553d8..a6d350a 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -2492,24 +2492,26 @@ def proxy_bypass_environment(host, proxies=None): try: no_proxy = proxies['no'] except KeyError: - return 0 + return False # '*' is special case for always bypass if no_proxy == '*': - return 1 + return True + host = host.lower() # strip port off host hostonly, port = _splitport(host) # check if the host ends with any of the DNS suffixes - no_proxy_list = [proxy.strip() for proxy in no_proxy.split(',')] - for name in no_proxy_list: + for name in no_proxy.split(','): + name = name.strip() if name: name = name.lstrip('.') # ignore leading dots - name = re.escape(name) - pattern = r'(.+\.)?%s$' % name - if (re.match(pattern, hostonly, re.I) - or re.match(pattern, host, re.I)): - return 1 + name = name.lower() + if hostonly == name or host == name: + return True + name = '.' + name + if hostonly.endswith(name) or host.endswith(name): + return True # otherwise, don't bypass - return 0 + return False # This code tests an OSX specific data structure but is testable on all @@ -2635,7 +2637,7 @@ elif os.name == 'nt': for p in proxyServer.split(';'): protocol, address = p.split('=', 1) # See if address has a type:// prefix - if not re.match('^([^/:]+)://', address): + if not re.match('(?:[^/:]+)://', address): address = '%s://%s' % (protocol, address) proxies[protocol] = address else: |