File 0006-CIDR-in-no_proxy.patch of Package ruby2.1
From fa32d7eba76b1deefb5f73cd43fc754947bb925b Mon Sep 17 00:00:00 2001
From: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Sat, 13 Feb 2016 08:31:12 +0000
Subject: [PATCH 06/13] CIDR in no_proxy
* lib/uri/generic.rb (URI::Generic#find_proxy): support CIDR in
no_proxy. [ruby-core:73769] [Feature#12062]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53817 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
---
lib/uri/generic.rb | 15 ++++++++++++---
test/uri/test_generic.rb | 8 ++++++++
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index 3dd6186b5e..4e10e54eb3 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -1663,9 +1663,18 @@ module URI
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
diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb
index 166763b40f..1478b64b69 100644
--- a/test/uri/test_generic.rb
+++ b/test/uri/test_generic.rb
@@ -800,6 +800,14 @@ class URI::TestGeneric < Test::Unit::TestCase
}
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)
--
2.12.0