Skip to content

Commit

Permalink
The spec says toUnicode returns the identity conversion on bad deco…
Browse files Browse the repository at this point in the history
…des.
  • Loading branch information
sporkmonger committed Dec 22, 2015
1 parent fb8efbf commit 295d7ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/addressable/idna/pure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ def self.to_unicode(input)
parts = input.split('.')
parts.map! do |part|
if part =~ /^#{ACE_PREFIX}(.+)/
punycode_decode(part[/^#{ACE_PREFIX}(.+)/, 1])
begin
punycode_decode(part[/^#{ACE_PREFIX}(.+)/, 1])
rescue Addressable::IDNA::PunycodeBadInput
# toUnicode is explicitly defined as never-fails by the spec
part
end
else
part
end
Expand Down
4 changes: 4 additions & 0 deletions spec/addressable/idna_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
end

shared_examples_for "converting from ASCII to unicode" do
it "should return the identity conversion when punycode decode fails" do
expect(Addressable::IDNA.to_unicode("xn--zckp1cyg1.sblo.jp")).to eq("xn--zckp1cyg1.sblo.jp")
end

it "should return the identity conversion when the ACE prefix has no suffix" do
expect(Addressable::IDNA.to_unicode("xn--...-")).to eq("xn--...-")
end
Expand Down

0 comments on commit 295d7ba

Please sign in to comment.