diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 7d7f2fa00d35b6..dd0246c6f37ea7 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1543,19 +1543,24 @@ def test_osx_proxy_bypass(self): '10.0/16'] } # Check hosts that should trigger the proxy bypass - for host in ('foo.bar', 'www.bar.com', '127.0.0.1', '10.10.0.1', + for hostonly in ('foo.bar', 'www.bar.com', '127.0.0.1', '10.10.0.1', '10.0.0.1'): - self.assertTrue(_proxy_bypass_macosx_sysconf(host, bypass), - 'expected bypass of %s to be True' % host) + for port in ('', ':80'): + host = hostonly + port + self.assertTrue(_proxy_bypass_macosx_sysconf(host, bypass), + 'expected bypass of %s to be True' % host) # Check hosts that should not trigger the proxy bypass - for host in ('abc.foo.bar', 'bar.com', '127.0.0.2', '10.11.0.1', + for hostonly in ('abc.foo.bar', 'bar.com', '127.0.0.2', '10.11.0.1', 'notinbypass'): - self.assertFalse(_proxy_bypass_macosx_sysconf(host, bypass), - 'expected bypass of %s to be False' % host) + for port in ('', ':80'): + host = hostonly + port + self.assertFalse(_proxy_bypass_macosx_sysconf(host, bypass), + 'expected bypass of %s to be False' % host) # Check the exclude_simple flag bypass = {'exclude_simple': True, 'exceptions': []} self.assertTrue(_proxy_bypass_macosx_sysconf('test', bypass)) + self.assertTrue(_proxy_bypass_macosx_sysconf('test:80', bypass)) # Check that invalid prefix lengths are ignored bypass = { diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 9a6b29a90a2968..b451698f665a20 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1981,7 +1981,7 @@ def ip2num(ipAddr): if (hostIP >> mask) == (base >> mask): return True - elif fnmatch(host, value): + elif fnmatch(hostonly, value): return True return False diff --git a/Misc/NEWS.d/next/macOS/2025-04-18-06-36-46.gh-issue-132671.FRLb6i.rst b/Misc/NEWS.d/next/macOS/2025-04-18-06-36-46.gh-issue-132671.FRLb6i.rst new file mode 100644 index 00000000000000..0f55e36ad42034 --- /dev/null +++ b/Misc/NEWS.d/next/macOS/2025-04-18-06-36-46.gh-issue-132671.FRLb6i.rst @@ -0,0 +1 @@ +Fix proxy bypass on URLs with a port in :mod:`urllib.request`.