ca6c97
From d52aaa5a5ebf281f96eac136ba68e63295c5bb8e Mon Sep 17 00:00:00 2001
ca6c97
From: usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
ca6c97
Date: Wed, 14 Jan 2015 06:55:00 +0000
ca6c97
Subject: [PATCH] merge revision(s) 48534: [Backport #10412]
ca6c97
ca6c97
	* lib/resolv.rb: fall back if canonicalization fails.
ca6c97
	  Thanks Vit Ondruch for the patch!  [ruby-core:65836]
ca6c97
ca6c97
	* test/resolv/test_dns.rb: test for patch
ca6c97
ca6c97
ca6c97
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@49245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
ca6c97
---
ca6c97
 ChangeLog               |  7 +++++++
ca6c97
 lib/resolv.rb           |  4 ++++
ca6c97
 test/resolv/test_dns.rb | 14 ++++++++++++++
ca6c97
 3 files changed, 25 insertions(+), 0 deletions(-)
ca6c97
ca6c97
diff --git a/ChangeLog b/ChangeLog
ca6c97
index 1aea7c0..8ea4238 100644
ca6c97
--- a/ChangeLog
ca6c97
+++ b/ChangeLog
ca6c97
@@ -1,3 +1,10 @@
ca6c97
+Wed Jan 14 15:54:18 2015  Aaron Patterson <aaron@tenderlovemaking.com>
ca6c97
+
ca6c97
+	* lib/resolv.rb: fall back if canonicalization fails.
ca6c97
+	  Thanks Vit Ondruch for the patch!  [ruby-core:65836]
ca6c97
+
ca6c97
+	* test/resolv/test_dns.rb: test for patch
ca6c97
+
ca6c97
 Thu Nov 13 22:31:50 2014  CHIKANAGA Tomoyuki  <nagachika@ruby-lang.org>
ca6c97
 
ca6c97
 	* lib/rexml/document.rb: add REXML::Document#document.
ca6c97
diff --git a/lib/resolv.rb b/lib/resolv.rb
ca6c97
index 53bfd54..a302d8a 100644
ca6c97
--- a/lib/resolv.rb
ca6c97
+++ b/lib/resolv.rb
ca6c97
@@ -1039,6 +1039,10 @@ def generate_candidates(name)
ca6c97
             candidates = []
ca6c97
           end
ca6c97
           candidates.concat(@search.map {|domain| Name.new(name.to_a + domain)})
ca6c97
+          fname = Name.create("#{name}.")
ca6c97
+          if !candidates.include?(fname)
ca6c97
+            candidates << fname
ca6c97
+          end
ca6c97
         end
ca6c97
         return candidates
ca6c97
       end
ca6c97
diff --git a/test/resolv/test_dns.rb b/test/resolv/test_dns.rb
ca6c97
index 07396fb..4d83d88 100644
ca6c97
--- a/test/resolv/test_dns.rb
ca6c97
+++ b/test/resolv/test_dns.rb
ca6c97
@@ -23,6 +23,20 @@ def with_udp(host, port)
ca6c97
     end
ca6c97
   end
ca6c97
 
ca6c97
+  # [ruby-core:65836]
ca6c97
+  def test_resolve_with_2_ndots
ca6c97
+    conf = Resolv::DNS::Config.new :nameserver => ['127.0.0.1'], :ndots => 2
ca6c97
+    assert conf.single?
ca6c97
+
ca6c97
+    candidates = []
ca6c97
+    conf.resolv('example.com') { |candidate, *args|
ca6c97
+      candidates << candidate
ca6c97
+      raise Resolv::DNS::Config::NXDomain
ca6c97
+    }
ca6c97
+    n = Resolv::DNS::Name.create 'example.com.'
ca6c97
+    assert_equal n, candidates.last
ca6c97
+  end
ca6c97
+
ca6c97
   def test_query_ipv4_address
ca6c97
     begin
ca6c97
       OpenSSL