summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/uri/generic.rb4
-rw-r--r--test/uri/test_generic.rb25
2 files changed, 27 insertions, 2 deletions
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index dcad27bc35..80d9616c1e 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -1531,14 +1531,14 @@ module URI
if (!port || self.port == port.to_i)
if /(\A|\.)#{Regexp.quote host}\z/i =~ self.host
return nil
- else
+ elsif addr
require 'ipaddr'
return nil if
begin
IPAddr.new(host)
rescue IPAddr::InvalidAddressError
next
- end.include?(self.host)
+ end.include?(addr)
end
end
}
diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb
index b226b2278b..1a470a6d18 100644
--- a/test/uri/test_generic.rb
+++ b/test/uri/test_generic.rb
@@ -839,6 +839,31 @@ class URI::TestGeneric < Test::Unit::TestCase
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_nil(URI("http://192.0.2.2/").find_proxy(env))
+
+ getaddress = IPSocket.method(:getaddress)
+ begin
+ class << IPSocket
+ undef getaddress
+ def getaddress(host)
+ host == "example.org" or raise
+ "192.0.2.1"
+ end
+ end
+ assert_equal(URI('http://127.0.0.1:8080'), URI.parse("http://example.org").find_proxy(env))
+ class << IPSocket
+ undef getaddress
+ def getaddress(host)
+ host == "example.org" or raise
+ "192.0.2.2"
+ end
+ end
+ assert_nil(URI.parse("http://example.org").find_proxy(env))
+ ensure
+ IPSocket.singleton_class.class_eval do
+ undef getaddress
+ define_method(:getaddress, getaddress)
+ end
+ end
}
with_proxy_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'example.org') {|env|
assert_nil(URI("http://example.org/").find_proxy(env))