Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed unf dependency for ruby > 2.2 #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion domain_name.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Suffix List.
"README.md"
]

gem.add_runtime_dependency("unf", ["< 1.0.0", ">= 0.0.5"])
gem.add_runtime_dependency("unf", ["< 1.0.0", ">= 0.0.5"]) if RUBY_VERSION < "2.2"
gem.add_development_dependency("test-unit", "~> 2.5.5")
gem.add_development_dependency("bundler", [">= 1.2.0"])
gem.add_development_dependency("rake", [">= 0.9.2.2", *("< 11" if RUBY_VERSION < "1.9")])
Expand Down
16 changes: 13 additions & 3 deletions lib/domain_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
require 'domain_name/version'
require 'domain_name/punycode'
require 'domain_name/etld_data'
require 'unf'
require 'ipaddr'
if RUBY_VERSION < '2.2'
require 'unf'
else
require 'unicode_normalize/normalize'
end

# Represents a domain name ready for extracting its registered domain
# and TLD.
Expand Down Expand Up @@ -285,8 +289,14 @@ def inspect
class << self
# Normalizes a _domain_ using the Punycode algorithm as necessary.
# The result will be a downcased, ASCII-only string.
def normalize(domain)
DomainName::Punycode.encode_hostname(domain.chomp(DOT).to_nfc).downcase
if RUBY_VERSION >= '2.2'
def normalize(domain)
DomainName::Punycode.encode_hostname(domain.chomp(DOT).unicode_normalize).downcase
end
else
def normalize(domain)
DomainName::Punycode.encode_hostname(domain.chomp(DOT).to_nfc).downcase
end
end
end
end
Expand Down
7 changes: 6 additions & 1 deletion test/test_domain_name-punycode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ class TestDomainName < Test::Unit::TestCase
'-> $1.00 <--']
].each { |title, cps, punycode|
assert_equal punycode, DomainName::Punycode.encode(cps.pack('U*')), title
assert_equal cps.pack('U*').to_nfc, DomainName::Punycode.decode(punycode), title
cps_norm = if RUBY_VERSION >= '2.2'
cps.pack('U*').unicode_normalize
else
cps.pack('U*').to_nfc
end
assert_equal cps_norm, DomainName::Punycode.decode(punycode), title
}
end
end