File Uri Scheme and Relative Files

前端 未结 6 1662
借酒劲吻你
借酒劲吻你 2020-12-01 00:59

Assume that the scheme for a uri is \"file\". Also assume that the path starts with \'.\'

An example path is \'./.bashrc\'. How would the fulluri look? \'file://./.

6条回答
  •  忘掉有多难
    2020-12-01 01:46

    It's impossible to use full file: URI with '.' or '..' segments in path without root part of that path. Whether you use 'file://./.bashrc' or 'file:///./.bashrc' these paths will have no sense. If you want to use a relative link, use it without protocol/authority part:

    link
    

    If you want to use full URI, you must tell a root relative to which your relative path is:

    link
    

    According to 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 describes even an algorithm of removing these "." and ".." from URI.

提交回复
热议问题