假定uri的方案是“文件”。还假设路径以“。”开头。
示例路径为“ ./.bashrc”。fulluri看起来如何?'file://./..bashrc'对我来说似乎很奇怪。
假定uri的方案是“文件”。还假设路径以“。”开头。
示例路径为“ ./.bashrc”。fulluri看起来如何?'file://./..bashrc'对我来说似乎很奇怪。
%20
=空格);根据应用程序的不同,您可能需要将转义字符替换为它们的实际表示形式。
Answers:
简而言之,文件URL的形式为:
file://localhost/absolute/path/to/file [ok]
或者,您可以省略主机(但不能省略斜线):
file:///absolute/path/to/file [ok]
但不是这个:
file://file_at_current_dir [no way]
也不是这样:
file://./file_at_current_dir [no way]
我刚刚通过Python的urllib2.urlopen()确认
来自http://en.wikipedia.org/wiki/File_URI_scheme的更多详细信息:
"file:///foo.txt" is okay, while "file://foo.txt" is not,
although some interpreters manage to handle the latter
http://
或https://
方案的网页内,则可以满足该条件。但是file://
,在OP提出的方案中,即使调用程序设法解释URI,它在语义上也取决于调用程序的CWD位置。实际上,file://
无论如何,您将在哪里使用该uri?如果它是CLI工具,则可以完全避免,file://
而只需退回到旧的本地路径即可。如果它在浏览器中,我们也不能假定其CWD。
不可能使用完整文件:带有'。'的URI。或路径中没有根部分的“ ..”段。无论您使用“ file://./..bashrc”还是“ file:///....bashrc”,这些路径都没有意义。如果要使用相对链接,请在没有协议/权限部分的情况下使用它:
<a href="./.bashrc">link</a>
如果要使用完整的URI,则必须告诉相对根,您的相对路径是:
<a href="file:///home/kindrik/./.bashrc">link</a>
根据RFC 3986
The path segments "." and "..", also known as dot-segments, are
defined for relative reference within the path name hierarchy. They
are intended for use at the beginning of a relative-path reference
(Section 4.2) to indicate relative position within the hierarchical
tree of names. This is similar to their role within some operating
systems' file directory structures to indicate the current directory
and parent directory, respectively. However, unlike in a file
system, these dot-segments are only interpreted within the URI path
hierarchy and are removed as part of the resolution process (Section
5.2).
The complete path segments "." and ".." are intended only for use
within relative references (Section 4.1) and are removed as part of
the reference resolution process (Section 5.2). However, some
deployed implementations incorrectly assume that reference resolution
is not necessary when the reference is already a URI and thus fail to
remove dot-segments when they occur in non-relative paths. URI
normalizers should remove dot-segments by applying the
remove_dot_segments algorithm to the path, as described in Section 5.2.4.
The complete path segments "." and ".." are intended only for use
within relative references (Section 4.1) and are removed as part of
the reference resolution process (Section 5.2)
RFC 3986甚至描述了删除这些“”的算法。和URI中的“ ..”。
在终端中,可以使用“ $ PWD”键入“ file://$PWD/.bashrc”以引用当前目录。
$PWD
包含类似空格的内容,C:/Users/Joshua Pinter/
则该路径将无效。需要以某种方式逃脱。
file://${PWD// /\\ }/relative/path
Invalid JSON-LD syntax; @context @id value must be an absolute IRI, a blank node identifier, or a keyword.
。我只想要一个相对编号,让我来做!