tel URI 中的加号是否应该编码?

Should the plus in tel URIs be encoded?

在 URI 中,空格可以编码为 +。既然如此,在创建带有国际前缀的tel URI时是否应该对前导加号进行编码?

哪个更好?两者在实践中都有效吗?

<a href="tel:+1234">Call me</a>
<a href="tel:%2B1234">Call me</a>

没有

来自 RFC 3966 的 section 3电话号码的电话 URI):

If the reserved characters "+", ";", "=", and "?" are used as delimiters between components of the "tel" URI, they MUST NOT be percent encoded.

你只会 percent-encode 一个 + 如果它是参数值的一部分:

These characters ["+", ";", "=", and "?"] MUST be percent encoded if they appear in tel URI parameter values.


我不确定前导的 + 表示它是一个 global number 是否算作分隔符,但是全局数字的定义是:

Globally unique numbers are identified by the leading "+" character.

所以它指的是 +,而不是 percent-encoded.

还有 examples 明确表示它不应该是 percent-encoded,例如:

tel:+1-201-555-0123

请注意,tel URI 中的 spaces(例如,在参数值中)可能不会使用 + 进行编码。对 space 字符使用 + 而不是 %20 不是任何 URI 都可以做的事情;只有在其 URI 方案明确定义的 URI 中才有可能。

tel: URI 方案没有编码 spaces 的规定 - 请参阅 RFC 3966:

    5.1.1.  Separators in Phone Numbers

    ...

    even though ITU-T E.123 [E.123] recommends the use of space
       characters as visual separators in printed telephone numbers, "tel"
       URIs MUST NOT use spaces in visual separators to avoid excessive
       escaping.

加号仅在 application/x-www-form-urlencoded 中专门对 space 进行编码(表单提交的默认内容类型 - 请参阅 W3C info re: forms)。没有在 tel: URI 中对 space 进行编码的有效方法。再次查看 RFC 3966(第 5 页)以获得有效的视觉分隔符。