中也可以看到此示例
Ruby的URI.join
似乎在将//injected_host
作为第二个参数给出时覆盖主机部件:
$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin13.4.0]
$ ruby -ruri -e 'puts URI.join("http://original.host/", "/path")'
http://original.host/path
$ ruby -ruri -e 'puts URI.join("http://original.host/", "//injected_host/path")'
http://injected_host/path
根据uri.join参考的JA_JP版本,此方法在RFC3986第5.2节之后进行。有人知道这种行为是否正确遵循RFC?
Ruby的实现是正确的。
URI-reference
以 //
为 relative-ref
开始, relative-part
是 "//" authority path-abempty
表格。根据pseudocode在RFC3986中的第5.2.2节中,如果给定的r是这样的,则简单地覆盖了权威,路径和查询。
if defined(R.scheme) then
(snip)
else
if defined(R.authority) then
T.authority = R.authority;
T.path = remove_dot_segments(R.path);
T.query = R.query;
else
(snip)
RFC3986第5.4节说http://a/b/c/d;p?q
和//g
产生http://g
。在RFC2396附录c。