IT Share you

파일 Uri 체계 및 상대 파일

shareyou 2020. 12. 15. 20:24
반응형

파일 Uri 체계 및 상대 파일


URI에 대한 체계가 "파일"이라고 가정합니다. 또한 경로가 '.'로 시작한다고 가정합니다.

예제 경로는 './.bashrc'입니다. 풀 루리는 어떻게 보일까요? 'file : //./.bashrc'가 이상하게 보입니다.


간단히 말해 파일 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

전체 파일 사용 불가 : 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"를 입력하여 현재 디렉토리를 참조 할 수 있습니다.


뒤에 이중 슬래시를 넣어서는 안됩니다 file:. 올바른 형태는

'file:.bashrc'

RFC 3986 , path-rootless정의 참조


귀하의 사용 사례를 모릅니다.

내 노드 코드에 비슷한 요구 사항이 있으므로 작업 디렉토리와 관련된 파일 URL이 필요할 때 다음과 같은 URL을 만듭니다.

const url = "file://" + process.cwd() + "/" + ".bashrc";

유닉스 쉘 스크립트에서 다음과 같이 사용할 수 있습니다.

file://`pwd`/relative-path

특별한 경우 :

file://`pwd`/.bashrc

참조 URL : https://stackoverflow.com/questions/7857416/file-uri-scheme-and-relative-files

반응형