[前][次][番号順一覧][スレッド一覧]

ruby-changes:51246

From: naruse <ko1@a...>
Date: Thu, 17 May 2018 16:40:06 +0900 (JST)
Subject: [ruby-changes:51246] naruse:r63452 (trunk): http_proxy setting should respect both parent domain and subdomain

naruse	2018-05-17 16:40:01 +0900 (Thu, 17 May 2018)

  New Revision: 63452

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63452

  Log:
    http_proxy setting should respect both parent domain and subdomain
    
    URI::Generic: Respect no_proxy for both parent domain and
    subdomains It is now possible to add just the subdomains for proxy bypass. In
    a setting where the main domain needs to go through proxy while the
    subdomains don't, it is now possible to just add the subdomains to the
    no_proxy list.
    The assumption that subdomains and the parent domain should
    behave the same wrt no_proxy has been removed.
    
    eg: Adding .example.com in no_proxy would allow example.com
    to go through the proxy.
    
    From: Harsimran Singh Maan <maan.harry@g...>
    fix https://github.com/ruby/ruby/pull/1748
    [Bug #14345]

  Modified files:
    trunk/lib/uri/generic.rb
    trunk/test/uri/test_generic.rb
Index: test/uri/test_generic.rb
===================================================================
--- test/uri/test_generic.rb	(revision 63451)
+++ test/uri/test_generic.rb	(revision 63452)
@@ -898,7 +898,7 @@ class URI::TestGeneric < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/uri/test_generic.rb#L898
       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::Tes https://github.com/ruby/ruby/blob/trunk/test/uri/test_generic.rb#L940
       ['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],
Index: lib/uri/generic.rb
===================================================================
--- lib/uri/generic.rb	(revision 63451)
+++ lib/uri/generic.rb	(revision 63452)
@@ -1543,11 +1543,16 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L1543
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]