Ruby URI 模块生成非法文件 URI [英] Ruby URI module produces illegal file-URI
本文介绍了Ruby URI 模块生成非法文件 URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是将文件路径转换为 URI 的后续问题.
考虑:
require 'uri'
uri = URI.join('file:///', '/home/user/dir1/dir2/dir3/name.ext')
=> #<URI::Generic:0x0000000263fcc0 URL:file:/home/user/dir1/dir2/dir3/name.ext>
uri.to_s
=> "file:/home/user/dir1/dir2/dir3/name.ext"
结果不是非法的吗?不应该是"file://home/..."
,带双斜线吗?
Isn't the result illegal? Shoudln't it be "file://home/..."
, with a double slash?
推荐答案
没有.file://home/...
指的是主机上名为home"的文件.完整的语法是file:///home/...
,带有三个斜杠,其中空的主机组件表示本地主机.然而,大多数识别文件"方案的 URI 解析器也接受只有一个斜杠的 file:/pathname
;缺少双斜线意味着跳过主机组件.
No. file://home/...
refers to a file on the host named 'home'. The full syntax is file:///home/...
, with three slashes, where the empty host component indicates the local host. However, most URI parsers that recognize the 'file' scheme also accept file:/pathname
with only one slash; the lack of doubled slashes means the host component is skipped.
这篇关于Ruby URI 模块生成非法文件 URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文