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?
No.
file://home/...refers to a file on the host named ‘home’. The full syntax isfile:///home/..., with three slashes, where the empty host component indicates the local host. However, most URI parsers that recognize the ‘file’ scheme also acceptfile:/pathnamewith only one slash; the lack of doubled slashes means the host component is skipped.