Feature Request: Support for IDNA
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 需要澄清
- 活跃度
- 冷清
- 技术栈
- ruby
- 领域
- networking
调研方向
首先查看 issue 中描述的 URI::Generic 的 host 和 hostname 行为,然后检查 resolv 库如何发出 DNS 查询。将提议的 uri/punycode 或 URI::Punycode API 与 libidn2 集成选项以及现有的可选依赖(如 openssl)进行比较。完成的要求是确定一致同意的 IDNA 2008 设计、依赖策略,以及 URI 解析和 DNS 解析的行为。
由索引模型根据 Issue 内容生成。
描述
Currently, the biggest "missing feature" in stdlib ruby URI/DNS resolution supply chain, is IDNA support. addressable, the OS alternative to stdlib uri, has some support for it, which is, I believe, the main reason why it is a transitive dependency from many other gems (It's other feature, uri templates, is just not as compelling).
This is a proposal for a way to solve this.
punycode
IDNA domains are translated to its punycode representation, in order to be used in DNS queries (which require ascii domains). ruby core stdlib does not have a punycode converter, so this is where it should start IMO. For that, I propose: either a new punycode stdlib gem (bundled?), or its functionality to be available as a submodule of URI in the uri stdlib:
# as a bundled gem
require "punycode"
Punycode.encode("l♥️h.ws") #=> "xn--lh-t0xz926h.ws"
Punycode.decode("xn--lh-t0xz926h.ws") #=> "l♥️h.ws"
# as internal functionality
require "uri/punycode"
URI::Punycode.encode(...
implementation
addressable, as well as other (mostly abandoned) gems, support the IDNA 2003 standard. You'll find both libidn based extensions, as well as pure ruby ports. This has been since superseded by the IDNA 2008 standard (which essentially supports all the more recent unicode versions, plus some edge cases). While I think that a pure ruby implementation should be entertained at some point, I think that at this point, ruby should do best by adopting the most standardized implementation around, and that's libidn2: it's used by most other network libraries, including curl, and distributed as a package for most (all?) OSes supported by ruby.
Integration of libidn2 can be done by either a C extension, or FFI (I'm the maintainer of idnx, which already FFI's into libidn2 and winnls for windows). The advantage of the latter is that it works OOTB for java. The disadvantage may be performance (?), for which a C extension may be a better fit, but then we'd need to know whether java stdlib contains an equivalent of IDNA conversion supporting IDNA 2008.
This means that libidn2 would become a dependency when building ruby. It could be dealt with, however, as an optional dependency, like openssl is: when available, URI::Punycode is defined, and when it isn't, URI::Punycode is not. most ruby installers could then opportunistically install the package as well, just like it's done already with openssl.
(addressable is aware of its lack of IDNA 2008 support, and is working on it by FFI'ing into libidn2 as well).
API
uri could then transparently handle translation internally. I propose that, beyond the proposal made above, nothing else in the public API changes. Instead URI::Generic would support translation OOTB on building objects:
uri = "https://l♥️h.ws"
uri = URI(uri)
uri.host #=> "l♥️h.ws"
uri.hostname #=> "xn--lh-t0xz926h.ws"
# the example above is inspired in how uri already handles IPv6 addresses
uri = URI("https://[::1]")
uri.host #=> "[::1]", cannot be used in Socket.new(host, port)
uri.hostname #=> "::1", can be used in Socket.new(host, port)
This could then be used internally in the resolv library, before issuing the DNS query.
- 主要语言
- Ruby
- 星标
- 125
- 派生
- 65
- 平均合并
- 6 小时 4 分钟
- 30 天内合并 PR
- 2
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/uri 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 48/100
-
难度 1/5 1 小时以内 新手友好度 25/100
-
难度 3/5 1-2 天 新手友好度 68/100
-
难度 3/5 1-2 天 新手友好度 52/100
-
难度 5/5 一周以上 新手友好度 35/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
-
bug
难度 1/5 1 小时以内 新手友好度 90/100
riscv/riscv-unified-db#2626 ·
-
Component: GLib
难度 2/5 1-3 小时 新手友好度 70/100
-
ds-drift
难度 2/5 1-3 小时 新手友好度 70/100
we-promise/sure#3693 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
simp/pupmod-simp-simp#395 ·