@@ -844,6 +844,29 @@ def test_should_bypass_proxies_no_proxy(url, expected, monkeypatch):
844844 assert should_bypass_proxies (url , no_proxy = no_proxy ) == expected
845845
846846
847+ @pytest .mark .parametrize (
848+ "url, expected" ,
849+ (
850+ ("http://localhost/" , True ),
851+ ("http://anotherdomain.com:8888/" , True ),
852+ ("http://newdomain.com:1234/" , True ),
853+ ("http://www.newdomain.com:1234/" , True ),
854+ ("http://foo.d.o.t/" , True ),
855+ ("http://d.o.t/" , True ),
856+ ("http://prelocalhost/" , False ),
857+ ("http://newdomain.com/" , False ),
858+ ("http://newdomain.com:1235/" , False ),
859+ ),
860+ )
861+ def test_should_bypass_proxies_no_proxy_domain_boundary (url , expected ):
862+ """Ensure no_proxy matching respects domain boundaries and does not
863+ greedily match domains that merely endswith the no_proxy entry.
864+ See CPython bpo-39057.
865+ """
866+ no_proxy = "localhost, anotherdomain.com, newdomain.com:1234, .d.o.t"
867+ assert should_bypass_proxies (url , no_proxy = no_proxy ) == expected
868+
869+
847870@pytest .mark .skipif (os .name != "nt" , reason = "Test only on Windows" )
848871@pytest .mark .parametrize (
849872 "url, expected, override" ,
0 commit comments