Подтвердить что ты не робот

Файл Uri Scheme и относительные файлы

Предположим, что схема для uri является "файлом". Также предположим, что путь начинается с '.'

Примерный путь:./.bashrc. Как будет выглядеть фулури? 'file://./.bashrc' мне кажется странным.

4b9b3361

Ответ 1

Короче говоря, 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

Ответ 2

Невозможно использовать полный файл: URI с '.' или '..' в пути без корневой части этого пути. Используете ли вы 'файл://./.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.

Ответ 3

В терминале вы можете ввести "file://$PWD/.bashrc", используя "$ PWD", чтобы обратиться к текущему каталогу.