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

ruby-changes:41743

From: nobu <ko1@a...>
Date: Sat, 13 Feb 2016 17:30:54 +0900 (JST)
Subject: [ruby-changes:41743] nobu:r53817 (trunk): CIDR in no_proxy

nobu	2016-02-13 17:31:12 +0900 (Sat, 13 Feb 2016)

  New Revision: 53817

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

  Log:
    CIDR in no_proxy
    
    * lib/uri/generic.rb (URI::Generic#find_proxy): support CIDR in
      no_proxy.  [ruby-core:73769] [Feature#12062]

  Modified files:
    trunk/ChangeLog
    trunk/lib/uri/generic.rb
    trunk/test/uri/test_generic.rb
Index: lib/uri/generic.rb
===================================================================
--- lib/uri/generic.rb	(revision 53816)
+++ lib/uri/generic.rb	(revision 53817)
@@ -1547,9 +1547,18 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L1547
       name = 'no_proxy'
       if no_proxy = ENV[name] || ENV[name.upcase]
         no_proxy.scan(/(?!\.)([^:,\s]+)(?::(\d+))?/) {|host, port|
-          if /(\A|\.)#{Regexp.quote host}\z/i =~ self.host &&
-            (!port || self.port == port.to_i)
-            return nil
+          if (!port || self.port == port.to_i)
+            if /(\A|\.)#{Regexp.quote host}\z/i =~ self.host
+              return nil
+            else
+              require 'ipaddr'
+              return nil if
+                begin
+                  IPAddr.new(host)
+                rescue IPAddr::InvalidAddressError
+                  next
+                end.include?(self.host)
+            end
           end
         }
       end
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53816)
+++ ChangeLog	(revision 53817)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Feb 13 17:30:49 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/uri/generic.rb (URI::Generic#find_proxy): support CIDR in
+	  no_proxy.  [ruby-core:73769] [Feature#12062]
+
 Sat Feb 13 17:11:58 2016  Fabian Wiesel  <fabian.wiesel@s...>
 
 	* lib/uri/generic.rb (find_proxy): exclude white-spaces and allow
Index: test/uri/test_generic.rb
===================================================================
--- test/uri/test_generic.rb	(revision 53816)
+++ test/uri/test_generic.rb	(revision 53817)
@@ -841,6 +841,14 @@ class URI::TestGeneric < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/uri/test_generic.rb#L841
     }
   end
 
+  def test_find_proxy_no_proxy_cidr
+    with_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'192.0.2.0/24') {
+      assert_equal(URI('http://127.0.0.1:8080'), URI("http://192.0.1.1/").find_proxy)
+      assert_nil(URI("http://192.0.2.1/").find_proxy)
+      assert_nil(URI("http://192.0.2.2/").find_proxy)
+    }
+  end
+
   def test_find_proxy_bad_value
     with_env('http_proxy'=>'') {
       assert_nil(URI("http://192.0.2.1/").find_proxy)

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

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