From 5a5a8de8d56abbb50f50e0052f7aa3e878007e6f Mon Sep 17 00:00:00 2001 From: z2s8 Date: Sun, 30 Oct 2016 00:39:08 +0200 Subject: [PATCH] Add support for un-encoded IDNs via addressable squash of 30b111f and ea8cb44 --- celluloid-dns.gemspec | 1 + lib/celluloid/dns/resolver.rb | 2 ++ spec/celluloid/dns/resolver_spec.rb | 16 ++++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/celluloid-dns.gemspec b/celluloid-dns.gemspec index 33908e9..f54f5fc 100644 --- a/celluloid-dns.gemspec +++ b/celluloid-dns.gemspec @@ -26,6 +26,7 @@ Gem::Specification.new do |spec| spec.add_dependency("celluloid", "~> 0.17.3") spec.add_dependency("celluloid-io", "~> 0.17.3") spec.add_dependency("timers", "~> 4.1.0") + spec.add_dependency("addressable", "~> 2.4.0") spec.add_development_dependency "bundler", "~> 1.3" spec.add_development_dependency "process-daemon", "~> 1.0.0" diff --git a/lib/celluloid/dns/resolver.rb b/lib/celluloid/dns/resolver.rb index 371e6c1..b598f7d 100644 --- a/lib/celluloid/dns/resolver.rb +++ b/lib/celluloid/dns/resolver.rb @@ -22,6 +22,7 @@ require 'securerandom' require 'celluloid/io' +require 'addressable' module Celluloid::DNS class InvalidProtocolError < StandardError @@ -71,6 +72,7 @@ def fully_qualified_name(name) end # ..else if we have a string, we need to do some basic processing: + name = Addressable::IDNA.to_ascii(name) unless name.ascii_only? if name.end_with? '.' return Resolv::DNS::Name.create(name) else diff --git a/spec/celluloid/dns/resolver_spec.rb b/spec/celluloid/dns/resolver_spec.rb index 63a9edc..cb1f17a 100755 --- a/spec/celluloid/dns/resolver_spec.rb +++ b/spec/celluloid/dns/resolver_spec.rb @@ -148,5 +148,21 @@ def handle_connection(socket) expect(addresses.size).to be > 0 end + + it "should resolve punycode encoded IDNs" do + resolver = Celluloid::DNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]]) + + addresses = resolver.addresses_for('xn--80ajiqg.xn--90ae') + + expect(addresses.size).to be > 0 + end + + it "should resolve raw UTF-8 IDNs" do + resolver = Celluloid::DNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]]) + + addresses = resolver.addresses_for('имена.бг') + + expect(addresses.size).to be > 0 + end end end