Ruby URI module produces illegal file-URI

限于喜欢 提交于 2019-12-22 09:07:03

问题


This is a follow-up question to Converting file path to URI.

Consider:

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"

Isn't the result illegal? Shoudln't it be "file://home/...", with a double slash?


回答1:


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.



来源:https://stackoverflow.com/questions/10571945/ruby-uri-module-produces-illegal-file-uri

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!