b8524a
From 423d042371d0402071c309dc403ea2701600a98b Mon Sep 17 00:00:00 2001
b8524a
From: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
b8524a
Date: Sat, 13 Feb 2016 08:12:21 +0000
b8524a
Subject: [PATCH] no_proxy with whitespaces and leading dots
b8524a
b8524a
* lib/uri/generic.rb (find_proxy): exclude white-spaces and allow
b8524a
  for a leading dot in the domain name in no_proxy.
b8524a
  [ruby-core:54542] [Feature #8317]
b8524a
b8524a
The previous implementation wouldn't allow for white-spaces nor a leading dot
b8524a
in the domain name. The latter is described in the wget documentation as a valid case.
b8524a
b8524a
By being more strict on the characters, which are counted to a domainname,
b8524a
we allow for white-spaces.
b8524a
Also, a possible leading dot will be handled gracefully.
b8524a
b8524a
[Fix GH-285]
b8524a
b8524a
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53816 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
b8524a
---
b8524a
 ChangeLog                | 6 ++++++
b8524a
 lib/uri/generic.rb       | 2 +-
b8524a
 test/uri/test_generic.rb | 4 ++++
b8524a
 3 files changed, 11 insertions(+), 1 deletion(-)
b8524a
b8524a
diff --git a/ChangeLog b/ChangeLog
b8524a
index 2945679..44116e0 100644
b8524a
--- a/ChangeLog
b8524a
+++ b/ChangeLog
b8524a
@@ -1,3 +1,9 @@
b8524a
+Sat Feb 13 17:11:58 2016  Fabian Wiesel  <fabian.wiesel@sap.com>
b8524a
+
b8524a
+	* lib/uri/generic.rb (find_proxy): exclude white-spaces and allow
b8524a
+	  for a leading dot in the domain name in no_proxy.
b8524a
+	  [ruby-core:54542] [Feature #8317]
b8524a
+
b8524a
 Sat Nov 30 13:28:13 2013  Nobuyoshi Nakada  <nobu@ruby-lang.org>
b8524a
 
b8524a
  * siphash.c (sip_hash24): fix for aligned word access little endian
b8524a
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
b8524a
index aba54c1..f2a2d56 100644
b8524a
--- a/lib/uri/generic.rb
b8524a
+++ b/lib/uri/generic.rb
b8524a
@@ -1662,7 +1662,7 @@ def find_proxy
b8524a
 
b8524a
       name = 'no_proxy'
b8524a
       if no_proxy = ENV[name] || ENV[name.upcase]
b8524a
-        no_proxy.scan(/([^:,]*)(?::(\d+))?/) {|host, port|
b8524a
+        no_proxy.scan(/(?!\.)([^:,\s]+)(?::(\d+))?/) {|host, port|
b8524a
           if /(\A|\.)#{Regexp.quote host}\z/i =~ self.host &&
b8524a
             (!port || self.port == port.to_i)
b8524a
             return nil
b8524a
diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb
b8524a
index fcfe1f9..ad189fc 100644
b8524a
--- a/test/uri/test_generic.rb
b8524a
+++ b/test/uri/test_generic.rb
b8524a
@@ -773,6 +773,14 @@ def test_find_proxy
b8524a
       assert_equal(URI('http://127.0.0.1:8080'), URI("http://192.0.2.1/").find_proxy)
b8524a
       assert_nil(URI("http://192.0.2.2/").find_proxy)
b8524a
     }
b8524a
+    with_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'example.org') {
b8524a
+      assert_nil(URI("http://example.org/").find_proxy)
b8524a
+      assert_nil(URI("http://www.example.org/").find_proxy)
b8524a
+    }
b8524a
+    with_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'.example.org') {
b8524a
+      assert_nil(URI("http://example.org/").find_proxy)
b8524a
+      assert_nil(URI("http://www.example.org/").find_proxy)
b8524a
+    }
b8524a
     with_env('http_proxy'=>'') {
b8524a
       assert_nil(URI("http://192.0.2.1/").find_proxy)
b8524a
       assert_nil(URI("ftp://192.0.2.1/").find_proxy)