summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/uri/generic.rb13
-rw-r--r--test/uri/test_generic.rb8
2 files changed, 16 insertions, 5 deletions
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index 799ad13471..0948cba66d 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -1543,11 +1543,16 @@ module URI
end
def self.use_proxy?(hostname, addr, port, no_proxy) # :nodoc:
- no_proxy.scan(/(?!\.)([^:,\s]+)(?::(\d+))?/) {|p_host, p_port|
+ hostname = hostname.downcase
+ dothostname = ".#{hostname}"
+ no_proxy.scan(/([^:,\s]+)(?::(\d+))?/) {|p_host, p_port|
if !p_port || port == p_port.to_i
- if /(\A|\.)#{Regexp.quote p_host}\z/i =~ hostname
- return false
- elsif addr
+ if p_host.start_with?('.')
+ return false if hostname.end_with?(p_host.downcase)
+ else
+ return false if dothostname.end_with?(".#{p_host.downcase}")
+ end
+ if addr
begin
return false if IPAddr.new(p_host).include?(addr)
rescue IPAddr::InvalidAddressError
diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb
index 31aa5c7552..c850eb02d1 100644
--- a/test/uri/test_generic.rb
+++ b/test/uri/test_generic.rb
@@ -898,7 +898,7 @@ class URI::TestGeneric < Test::Unit::TestCase
assert_nil(URI("http://www.example.org/").find_proxy(env))
}
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))
+ assert_equal(URI('http://127.0.0.1:8080'), URI("http://example.org/").find_proxy(env))
assert_nil(URI("http://www.example.org/").find_proxy(env))
}
end
@@ -940,7 +940,13 @@ class URI::TestGeneric < Test::Unit::TestCase
['example.com', nil, 80, 'example.com:80', false],
['example.com', nil, 80, 'example.org,example.com:80,example.net', false],
['foo.example.com', nil, 80, 'example.com', false],
+ ['foo.example.com', nil, 80, '.example.com', false],
+ ['example.com', nil, 80, '.example.com', true],
+ ['xample.com', nil, 80, '.example.com', true],
+ ['fooexample.com', nil, 80, '.example.com', true],
['foo.example.com', nil, 80, 'example.com:80', false],
+ ['foo.eXample.com', nil, 80, 'example.com:80', false],
+ ['foo.example.com', nil, 80, 'eXample.com:80', false],
['foo.example.com', nil, 80, 'example.com:443', true],
['127.0.0.1', '127.0.0.1', 80, '10.224.0.0/22', true],
['10.224.1.1', '10.224.1.1', 80, '10.224.1.1', false],