diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index 6fd0f7c..bef814d 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -1568,9 +1568,13 @@ def find_proxy(env=ENV) end def self.use_proxy?(hostname, addr, port, no_proxy) # :nodoc: + no_proxy_entries = no_proxy.scan(/([^:,\s]+)(?::(\d+))?/) + return false if no_proxy_entries.any? { |entry, _| entry == '*' } + hostname = hostname.downcase dothostname = ".#{hostname}" - no_proxy.scan(/([^:,\s]+)(?::(\d+))?/) {|p_host, p_port| + + no_proxy_entries.each {|p_host, p_port| if !p_port || port == p_port.to_i if p_host.start_with?('.') return false if hostname.end_with?(p_host.downcase) diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb index 94eea71..d82ef5b 100644 --- a/test/uri/test_generic.rb +++ b/test/uri/test_generic.rb @@ -965,6 +965,9 @@ def test_find_proxy_no_proxy 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)) } + with_proxy_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'*') {|env| + assert_nil(URI("http://www.example.org/").find_proxy(env)) + } ensure IPSocket.singleton_class.class_eval do undef getaddress @@ -1008,8 +1011,10 @@ def test_use_proxy_p ['example.com', nil, 80, '', true], ['example.com', nil, 80, 'example.com:80', false], ['example.com', nil, 80, 'example.org,example.com:80,example.net', false], + ['example.com', nil, 80, 'example.org,*', false], ['foo.example.com', nil, 80, 'example.com', false], ['foo.example.com', nil, 80, '.example.com', false], + ['foo.example.com', nil, 80, '*.example.com', true], ['example.com', nil, 80, '.example.com', true], ['xample.com', nil, 80, '.example.com', true], ['fooexample.com', nil, 80, '.example.com', true], @@ -1020,6 +1025,7 @@ def test_use_proxy_p ['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], ['10.224.1.1', '10.224.1.1', 80, '10.224.0.0/22', false], + ['10.224.1.1', '10.224.1.1', 80, '*', false], ].each do |hostname, addr, port, no_proxy, expected| assert_equal expected, URI::Generic.use_proxy?(hostname, addr, port, no_proxy), "use_proxy?('#{hostname}', '#{addr}', #{port}, '#{no_proxy}')"