当没有 www 时,ruby toUnicode fun 不会返回 IDN 站点。在网址中

发布于 2024-09-13 16:27:04 字数 591 浏览 2 评论 0原文

在我的 Rails 应用程序中,我将 idn url 转换为 punycode,然后再转换回 idn。

但是如果我有这样的网址 http://日本语.jp(不带 www。)

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

但尝试将其转换回 IDN 会失败,

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

如果我们只添加 www,则 toUnicode 无法正确转换回来。到上面的 idn url,例如 http://www.日本语.jp< /a>

我错过了什么吗?

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??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

强者自强 2024-09-20 16:27:04

终于想通了。问题是 url 中的 http 部分。 toUnicode 的乐趣工作得很好。如果我们删除 url 中的 http 部分并传递它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文