RFC 3986 Uniform Resource Identifier (IRI) において userinfo コンポーネント内の詳細な文法は規定されていなくてだいぶ雑なんだけど、 validator がどこまで検査するか悩ましい
RFC 3986: Uniform Resource Identifier (URI): Generic Syntax
https://www.rfc-editor.org/rfc/rfc3986.html#section-3.2.1
> userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
>
> Use of the format "user:password" in the userinfo field is deprecated.
旧規格の RFC 2396 も言及がかなり微妙
RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax
https://www.rfc-editor.org/rfc/rfc2396#section-3.2.2
> userinfo = *( unreserved | escaped |
> ";" | ":" | "&" | "=" | "+" | "$" | "," )
>
> Some URL schemes use the format "user:password" in the userinfo field.
> This practice is NOT RECOMMENDED, because (以下略)
RFC 1738: Uniform Resource Locators (URL)
https://www.rfc-editor.org/rfc/rfc1738#section-3.1
> Within the user and password field, any ":", "@", or "/" must be encoded.
なるほどね?
つまり何が問題かというと、 RFC 1738 時代の URL においては user:pass の user, pass 部分のコロンはエスケープすべしという明示があったんだけど、 RFC 2396 (URI), RFC 3986 (URI) においてはその旨の記述が消えておりコロンは何度でも出現できることになっている。
では、たとえば foo:bar:baz @ example.com のような URI を作ろうとしているとき validator および builder はどのように反応すべきか
RFC 3986 では以下のように言っており、 (まあ安全側に倒せば当然ではあるが) 最初のコロン以降は基本的に全部パスワード扱いしようということになっている
> Applications should not render as clear text any data after the first colon (":") character found within a userinfo subcomponent unless (以下略)
validator と safe serialization においては任意個のコロンを許容して最初のコロン以降全部パスワード扱いすればいいんだけど、 builder はどうすべきか
たとえばエスケープされていないコロンを慣習に沿っていないとして拒絶するのもアリだろうし、引数次第では自動エスケープするのも考えられなくはないし、あるいは user / password でそもそも区別して受け入れるべきではない (ユーザに userinfo を手動で合成させるべき) かもしれない