Search code examples
rubyidn

ruby toUnicode fun does not return the idn site when there is no www. in the url


In my rails app, i convert a idn url to punycode and back to idn.

But if i have a url like this http://日本語.jp (without www.)

domain = "http://日本語.jp"
punycode = Idna.toAscii(domain)  => http://xn--blagzdfd.com

but trying to convert it backto IDN fails

 idn = Idna.toUnicode(punycode) =>        xn--blagzdfd.com instead of http://日本語.jp

the toUnicode converts back properly if we just add www. to the above idn url like http://www.日本語.jp

am i missing something??


Solution

  • finally figured it out. the problem was the http part in the url. the toUnicode fun works fine. if we remove the http part in the url and pass it.