diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index dcad27bc350175..e885657d4674d1 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -1535,10 +1535,10 @@ def find_proxy(env=ENV) require 'ipaddr' return nil if begin - IPAddr.new(host) + IPAddr.new(host).include?(self.host) rescue IPAddr::InvalidAddressError next - end.include?(self.host) + end end end } diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb index b226b2278b83d0..355b0bac177b89 100644 --- a/test/uri/test_generic.rb +++ b/test/uri/test_generic.rb @@ -838,6 +838,7 @@ def test_find_proxy_get def test_find_proxy_no_proxy with_proxy_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'192.0.2.2') {|env| assert_equal(URI('http://127.0.0.1:8080'), URI("http://192.0.2.1/").find_proxy(env)) + assert_equal(URI('http://127.0.0.1:8080'), URI("http://example.org/").find_proxy(env)) assert_nil(URI("http://192.0.2.2/").find_proxy(env)) } with_proxy_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'example.org') {|env|