Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Commit

Permalink
Add support for un-encoded IDNs via addressable
Browse files Browse the repository at this point in the history
squash of 30b111f and ea8cb44
  • Loading branch information
z2s8 committed Oct 30, 2016
1 parent 6118508 commit 5a5a8de
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions celluloid-dns.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions lib/celluloid/dns/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

require 'securerandom'
require 'celluloid/io'
require 'addressable'

module Celluloid::DNS
class InvalidProtocolError < StandardError
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions spec/celluloid/dns/resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5a5a8de

Please sign in to comment.